improve things
This commit is contained in:
parent
fbfd89fc12
commit
651cd28698
@ -169,8 +169,9 @@ async function init () {
|
||||
if (uploadedFiles.length === 0) return res.status(400).send('No files were uploaded')
|
||||
let tagify = fields && fields['tagify']
|
||||
if (tagify != null) {
|
||||
let a = uploadedFiles.length > 1 ? ' target="_blank"' : ''
|
||||
for (let i in uploadedFiles) {
|
||||
uploadedFiles[i] = '<a href="' + uploadedFiles[i] + '" target="_blank">' + uploadedFiles[i] + '</a>'
|
||||
uploadedFiles[i] = '<a href="' + uploadedFiles[i] + '"' + a + '>' + uploadedFiles[i] + '</a>'
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,23 +199,28 @@ async function init () {
|
||||
}
|
||||
|
||||
let db = await dbPromise
|
||||
|
||||
// Get a hash that isnt in use
|
||||
let use
|
||||
for (let i = 0; i < 8; i++) {
|
||||
let add = Math.floor(i / 2)
|
||||
let hash = crypto.randomBytes((config.shortener.bytes || 2) + add).toString('hex')
|
||||
let exists = await db.get('SELECT timeat FROM Short WHERE hash = ?', hash)
|
||||
if (!exists) {
|
||||
use = hash
|
||||
break
|
||||
let existing = await db.get('SELECT hash FROM Short WHERE url = ?', url)
|
||||
|
||||
if (existing) {
|
||||
use = existing.hash
|
||||
} else {
|
||||
// Get a hash that isnt in use
|
||||
for (let i = 0; i < 8; i++) {
|
||||
let add = Math.floor(i / 2)
|
||||
let hash = crypto.randomBytes((config.shortener.bytes || 2) + add).toString('hex')
|
||||
let exists = await db.get('SELECT timeat FROM Short WHERE hash = ?', hash)
|
||||
if (!exists) {
|
||||
use = hash
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!use) throw new Error('Server could not find a proper hash for some reason')
|
||||
|
||||
await db.run('INSERT INTO Short (url,hash,timeat,ip) VALUES (?,?,?,?)', url, use, Date.now(), ip)
|
||||
}
|
||||
|
||||
if (!use) throw new Error('Server could not find a proper hash for some reason')
|
||||
|
||||
await db.run('INSERT INTO Short (url,hash,timeat,ip) VALUES (?,?,?,?)', url, use, Date.now(), ip)
|
||||
|
||||
let ua = req.get('User-Agent')
|
||||
let reqRaw = false
|
||||
if (!reqRaw && ua && (ua.match(/curl\//i) != null || ua.match(/wget\//i) != null)) reqRaw = true
|
||||
|
Loading…
Reference in New Issue
Block a user