41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import "dotenv/config"
|
|
|
|
import * as Minio from 'minio'
|
|
import Vision from '@google-cloud/vision'
|
|
import { PrismaClient } from '@prisma/client'
|
|
|
|
import discordScraper from './src/scraper'
|
|
|
|
const VISION_CREDENTIALS = (await import(process.env.GOOGLE_APPLICATION_CREDENTIALS, { assert: { type: "json" } })).default
|
|
const STORAGE_BUCKET = process.env.STORAGE_BUCKET
|
|
|
|
const minio = new Minio.Client({
|
|
endPoint: process.env.STORAGE_URL,
|
|
accessKey: process.env.STORAGE_ACCESS_KEY,
|
|
secretKey: process.env.STORAGE_SECRET_KEY,
|
|
})
|
|
const vision = new Vision.ImageAnnotatorClient({ credentials: VISION_CREDENTIALS })
|
|
const prisma = new PrismaClient()
|
|
|
|
async function storageBucketExists() {
|
|
const exists = await minio.bucketExists(STORAGE_BUCKET)
|
|
if (exists) return true
|
|
await minio.makeBucket(STORAGE_BUCKET)
|
|
}
|
|
|
|
console.log(await storageBucketExists())
|
|
|
|
// BIGINTS
|
|
// must be strings
|
|
const CHANNEL_IDS = [
|
|
'367936426962190336', // TPM shitposts
|
|
'1095060717117374687', // aella memes
|
|
]
|
|
|
|
const scraper = discordScraper(process.env.DISCORD_AUTH, vision, minio)
|
|
|
|
const msgs = await Promise.all(CHANNEL_IDS.map(c => scraper.getChannelAttachments(c)))
|
|
console.log(msgs)
|
|
const downloads = await Promise.all(msgs.flat().map(scraper.downloadAttachment))
|
|
|