-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7060a6
commit 390fca3
Showing
6 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const axios = require('axios'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const filePath = path.join(__dirname, './svg'); | ||
const files = fs.readdirSync(filePath).map((fileName) => ({ | ||
path: `${filePath}/${fileName}`, | ||
name: fileName.split('.')[0], | ||
type: fileName.split('.')[1], | ||
})); | ||
|
||
function chunkArray(array, chunkSize) { | ||
const result = []; | ||
for (let i = 0; i < array.length; i += chunkSize) { | ||
result.push(array.slice(i, i + chunkSize)); | ||
} | ||
return result; | ||
} | ||
const filesArray = chunkArray(files, 10); | ||
|
||
let i = 0; | ||
setInterval(async () => { | ||
if (i >= filesArray.length) { | ||
console.log('已经上传完毕'); | ||
return; | ||
} | ||
try { | ||
const result = await axios.post( | ||
'http://localhost:3000/logos/uploadImgByCode', | ||
filesArray[i], | ||
); | ||
console.log(result); | ||
} catch (e) { | ||
console.log(e); | ||
i--; | ||
} | ||
i++; | ||
console.log(i * 10); | ||
}, 60000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { createConnector } = require('@lxdao/uploader3-connector'); | ||
|
||
const connector = createConnector('NFT.storage', { | ||
token: process.env.IPFS_TOKEN, | ||
}); | ||
|
||
export default async (files) => { | ||
const imgData = files.map(async (i) => { | ||
const fileData = fs.readFileSync(i.path); | ||
const buffer = Buffer.from(fileData).toString('base64'); | ||
const result = await connector.postImage({ data: buffer, type: i.type }); | ||
return { ...i, url: result.url } as { | ||
name: string; | ||
url: string; | ||
type: string; | ||
}; | ||
}); | ||
return Promise.all([...imgData]); | ||
}; |