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')
|
if (uploadedFiles.length === 0) return res.status(400).send('No files were uploaded')
|
||||||
let tagify = fields && fields['tagify']
|
let tagify = fields && fields['tagify']
|
||||||
if (tagify != null) {
|
if (tagify != null) {
|
||||||
|
let a = uploadedFiles.length > 1 ? ' target="_blank"' : ''
|
||||||
for (let i in uploadedFiles) {
|
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,9 +199,13 @@ async function init () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let db = await dbPromise
|
let db = await dbPromise
|
||||||
|
|
||||||
// Get a hash that isnt in use
|
|
||||||
let use
|
let use
|
||||||
|
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++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
let add = Math.floor(i / 2)
|
let add = Math.floor(i / 2)
|
||||||
let hash = crypto.randomBytes((config.shortener.bytes || 2) + add).toString('hex')
|
let hash = crypto.randomBytes((config.shortener.bytes || 2) + add).toString('hex')
|
||||||
@ -214,6 +219,7 @@ async function init () {
|
|||||||
if (!use) throw new Error('Server could not find a proper hash for some reason')
|
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)
|
await db.run('INSERT INTO Short (url,hash,timeat,ip) VALUES (?,?,?,?)', url, use, Date.now(), ip)
|
||||||
|
}
|
||||||
|
|
||||||
let ua = req.get('User-Agent')
|
let ua = req.get('User-Agent')
|
||||||
let reqRaw = false
|
let reqRaw = false
|
||||||
|
Loading…
Reference in New Issue
Block a user