initial commit

This commit is contained in:
pablof7z
2023-07-08 13:49:12 +02:00
commit 281c7b1c65
29 changed files with 4415 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import { NDKTag } from '@nostr-dev-kit/ndk';
import axios from 'axios';
import fs from 'fs';
export async function fetchFileFromInput(input: NDKTag): Promise<string> {
switch (input[2]) {
case 'url': {
const url = input[1];
const fileExtension = url.split('.').pop();
// download the file
// save it to the local filesystem
// return the path to the file
const response = await axios.get(url, {
responseType: 'stream'
});
const randomName = Math.random().toString(36).substring(7);
const path = `./${randomName}.${fileExtension}`;
await response.data.pipe(fs.createWriteStream(path));
return path;
}
}
return undefined;
}