Skip to content
Snippets Groups Projects
Verified Commit 08492502 authored by Louis's avatar Louis :fire:
Browse files

Script for checking upload status

parent 8be06cdd
No related branches found
No related tags found
No related merge requests found
async function main() {
const { URL } = require('url')
const { Upload } = require('database/models')
const { fs } = require('services')
let uploads = []
const total = await Upload.count({ where: { status: 'pending' } })
let count = 0
uploads = await Upload.findAll({ limit: 25, order: ['created_at'], where: { status: 'pending' } })
while (uploads.length > 0) {
console.log('Processing entries %d to %d, of total %d', count, count + uploads.length, total)
count += uploads.length
for (const upload of uploads) {
await new Promise(r => setTimeout(r, 50))
// const path = `${ upload.user_id }/${ upload.id }.jpg`
const url = new URL(upload.upload_url)
url.search = ''
const [_, bucket, ...pathParts] = url.pathname.split('/')
const path = pathParts.join('/')
try {
await fs.makePublic(path)
} catch(e) {
console.error('Couldnt make ', path, ' public')
upload.status = 'failed'
upload.status_reason = 'bogus upload url'
await upload.save()
continue
}
console.log(url.toString())
upload.status = 'success'
await upload.save()
}
await new Promise(r => setTimeout(r, 500))
uploads = await Upload.findAll({ limit: 25, order: ['created_at'], where: { status: 'pending' } })
}
process.exit(0)
}
main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment