-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.mjs
45 lines (34 loc) · 1.18 KB
/
utils.mjs
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
import "dotenv/config";
import knex from "knex";
import PQueue from "p-queue";
export const messagesUrl = process.env.MESSAGES_URL;
export const url3 = process.env.API_URL_3;
export const url4 = process.env.API_URL_4;
export const log = (data) =>
`${console.log(JSON.stringify(data, null, 2))}\n\n`;
export const getIntro = (str = "") => (str ? str.split(".")[0] : null);
const connection4 = process.env.DB_CONNECTION_4;
export const db = knex({
client: "pg",
connection: connection4,
});
export const largeQueue = new PQueue({ concurrency: 32 });
export const queue = new PQueue({ concurrency: 16 });
export const singleQueue = new PQueue({ concurrency: 1 });
export const getFormat = (obj, format) => {
if (obj[format]) return obj[format];
if (!obj[format] && format === "large" && obj.medium) {
return obj.medium;
}
if (!obj[format] && format === "large" && obj.small) {
return obj.small;
}
if (!obj[format] && format === "medium" && obj.small) {
return obj.small;
}
if (!obj[format] && format === "thumbnail" && obj.small) return obj.small;
if (!obj.large && !obj.medium && !obj.small && obj.thumbnail) {
return obj.thumbnail;
}
return null;
};