( token: string, channelId: string, logger: Logger )
| 78 | } |
| 79 | |
| 80 | function processLink( |
| 81 | token: string, |
| 82 | channelId: string, |
| 83 | logger: Logger |
| 84 | ): (file: MessageFile) => Promise<{ fileId?: string; internalUrl?: string }> { |
| 85 | return async function (file: MessageFile) { |
| 86 | if (!file.url_private) return {}; |
| 87 | try { |
| 88 | const response = await fetchFile(file.url_private, token); |
| 89 | const ext = path.extname(file.name); |
| 90 | const name = slugify(file.name.substring(0, file.name.indexOf(ext))); |
| 91 | |
| 92 | const s3Key = [ |
| 93 | BUCKET_PREFIX_FOR_ATTACHMENTS, |
| 94 | channelId, |
| 95 | random() + name + ext, |
| 96 | ].join('/'); |
| 97 | |
| 98 | await uploadFile({ |
| 99 | Key: s3Key, |
| 100 | Body: Buffer.from(response.text || response.body), |
| 101 | }); |
| 102 | return { |
| 103 | fileId: file.id, |
| 104 | internalUrl: [LINEN_STATIC_CDN, s3Key].join('/'), |
| 105 | }; |
| 106 | } catch (error) { |
| 107 | logger.error({ error }); |
| 108 | return {}; |
| 109 | } |
| 110 | }; |
| 111 | } |
| 112 | |
| 113 | function arrayToMapGeneric(key: string, val: string) { |
| 114 | return (prev: any, curr: any) => { |
no test coverage detected