({
attach,
accountId,
channelId,
name,
ext,
}: {
attach: DiscordAttachments;
accountId: string | null;
channelId: string;
name: string;
ext: string;
})
| 48 | } |
| 49 | |
| 50 | async function upload({ |
| 51 | attach, |
| 52 | accountId, |
| 53 | channelId, |
| 54 | name, |
| 55 | ext, |
| 56 | }: { |
| 57 | attach: DiscordAttachments; |
| 58 | accountId: string | null; |
| 59 | channelId: string; |
| 60 | name: string; |
| 61 | ext: string; |
| 62 | }) { |
| 63 | try { |
| 64 | const response = await axios.get(attach.url || attach.proxy_url, { |
| 65 | responseType: 'arraybuffer', |
| 66 | }); |
| 67 | if (response.data) { |
| 68 | const s3Key = [ |
| 69 | BUCKET_PREFIX_FOR_ATTACHMENTS, |
| 70 | accountId, |
| 71 | channelId, |
| 72 | random() + name + ext, |
| 73 | ] |
| 74 | .filter((e) => e) |
| 75 | .join('/'); |
| 76 | await uploadFile({ Key: s3Key, Body: response.data }); |
| 77 | return [LINEN_STATIC_CDN, s3Key].join('/'); |
| 78 | } |
| 79 | } catch (error) { |
| 80 | console.error(error); |
| 81 | } |
| 82 | return null; |
| 83 | } |
no test coverage detected