Created
November 1, 2021 07:11
-
-
Save rafinskipg/91d4a4447e871cb6b08a0e385e80f674 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type FileNft = { | |
path: string, | |
name: string | |
} | |
export async function storeDirectory(files: FileNft[]) { | |
try { | |
const client = new NFTStorage({ | |
token: process.env.NFT_STORAGE_KEY as string, | |
}); | |
const f = []; | |
for(var i = 0; i < files.length; i++) { | |
const file: FileNft = files[i] | |
console.log('Reading', file.path) | |
f.push(new File([fs.readFileSync(file.path)], file.name)) | |
} | |
console.log('Storing') | |
return await client.storeDirectory(f); | |
} catch (e) { | |
console.error(e.message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment