-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (33 loc) · 965 Bytes
/
index.js
File metadata and controls
41 lines (33 loc) · 965 Bytes
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
import alfy from 'alfy';
import { getSelectionFilsPath } from "./lib/getSelectionFilsPath.js"
import { uploadImage } from "./lib/gyazoClient.js"
import { isValidFileType } from "./lib/validate";
import alfredNotifier from "alfred-notifier";
alfredNotifier();
const TARGET_FILE_TYPES = ["jpg", "png", "gif"];
const API_TOKEN = process.env.GYAZO_API_TOKEN
const main = async () => {
const files = await getSelectionFilsPath();
if (files.length !== 1) {
console.log('Multiple files selected.');
return
}
const file = files[0];
const isValid = await isValidFileType(file, TARGET_FILE_TYPES)
if (!isValid) {
console.log('Invalid file type selected.')
return
}
if(!API_TOKEN){
console.log('Gyazo API TOKEN is not set.')
return
}
try {
const res = await uploadImage(file, API_TOKEN)
console.log(``)
} catch(e) {
console.log('Gyazo API token is invalid.')
alfy.log(e)
}
}
await main();