MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / processLink

Function processLink

apps/web/services/slack/sync/attachments.ts:80–111  ·  view source on GitHub ↗
(
  token: string,
  channelId: string,
  logger: Logger
)

Source from the content-addressed store, hash-verified

78}
79
80function 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
113function arrayToMapGeneric(key: string, val: string) {
114 return (prev: any, curr: any) => {

Callers 1

processLinksFunction · 0.85

Calls 5

fetchFileFunction · 0.90
slugifyFunction · 0.90
uploadFileFunction · 0.90
errorMethod · 0.65
randomFunction · 0.50

Tested by

no test coverage detected