-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
59 lines (48 loc) · 1.45 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { promises as fsPromises } from "fs"
import * as path from "path"
import * as emojme from "emojme"
const slackTokenJson = JSON.parse(Bun.env.SLACK_TOKEN_JSON!)
const directoryPath = path.join(import.meta.dir, "emoji")
async function getFilePaths(dir: string) {
let filePaths: string[] = []
try {
const files = await fsPromises.readdir(dir, { withFileTypes: true })
for (const file of files) {
const fullPath = path.join(dir, file.name)
if (file.name.startsWith("_")) {
console.log(`Skipped: ${fullPath}`)
continue
}
if (file.isDirectory()) {
filePaths.push(...(await getFilePaths(fullPath)))
} else if (file.name.match(/\.(gif|jpg|jpeg|png)/)) {
filePaths.push(fullPath)
} else {
console.info(`Skipped: ${fullPath}`)
continue
}
}
} catch (err: any) {
console.error(`Error reading directory: ${err.message}`)
}
return filePaths
}
async function upload() {
const filePaths = await getFilePaths(directoryPath)
const emojiList = filePaths.map((filePath) => {
const name = path.basename(filePath, path.extname(filePath))
return {
name,
is_alias: 0,
alias_for: null,
url: filePath,
}
})
const { domain, token, cookie } = slackTokenJson
const result = await emojme.upload(domain, token, cookie, {
src: emojiList as unknown as any,
verbose: true,
})
console.info(result[domain])
}
await upload()