(file: {
id: string;
filename: string;
contentType?: string;
url: string;
})
| 13 | }); |
| 14 | |
| 15 | export async function uploadFileFromUrl(file: { |
| 16 | id: string; |
| 17 | filename: string; |
| 18 | contentType?: string; |
| 19 | url: string; |
| 20 | }) { |
| 21 | if (sharedEnvs.NODE_ENV === 'test') return null; |
| 22 | const res = await fetch(file.url); |
| 23 | if (!res.ok || !res.body) return null; |
| 24 | const stream = Readable.fromWeb( |
| 25 | res.body as unknown as ReadableStream<Uint8Array>, |
| 26 | ); |
| 27 | return new Upload({ |
| 28 | client: s3bucket, |
| 29 | params: { |
| 30 | Bucket: sharedEnvs.BUCKET_NAME as string, |
| 31 | |
| 32 | Key: `${file.id}/${file.filename}`, |
| 33 | Body: stream, |
| 34 | ContentDisposition: 'inline', |
| 35 | ContentType: file.contentType, |
| 36 | }, |
| 37 | }).done(); |
| 38 | } |
| 39 | |
| 40 | export async function uploadFile(file: { |
| 41 | filename: string; |
no test coverage detected