Postgres.
This commit is contained in:
parent
695644c260
commit
806f42e3f8
25 changed files with 501 additions and 294 deletions
|
@ -1,5 +1,6 @@
|
|||
import { join } from 'path';
|
||||
import mime from 'mime-types';
|
||||
import models from '../../models';
|
||||
import hostrFileStream from '../../lib/hostr-file-stream';
|
||||
import { formatFile } from '../../lib/format';
|
||||
|
||||
|
@ -32,36 +33,38 @@ export function* get() {
|
|||
return;
|
||||
}
|
||||
|
||||
const file = yield this.db.Files.findOne({
|
||||
_id: this.params.id,
|
||||
file_name: this.params.name,
|
||||
status: 'active',
|
||||
const file = yield models.file.findOne({
|
||||
where: {
|
||||
id: this.params.id,
|
||||
name: this.params.name,
|
||||
status: 'active',
|
||||
},
|
||||
});
|
||||
this.assert(file, 404);
|
||||
|
||||
if (!hotlinkCheck(file, this.headers['user-agent'], this.headers.referer)) {
|
||||
this.redirect(`/${file._id}`);
|
||||
this.redirect(`/${file.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file.width && this.request.query.warning !== 'on') {
|
||||
this.redirect(`/${file._id}`);
|
||||
this.redirect(`/${file.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.malware) {
|
||||
const alert = this.request.query.alert;
|
||||
if (!alert || !alert.match(/i want to download malware/i)) {
|
||||
this.redirect(`/${file._id}`);
|
||||
this.redirect(`/${file.id}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let localPath = join(storePath, file._id[0], `${file._id}_${file.file_name}`);
|
||||
let remotePath = join(file._id[0], `${file._id}_${file.file_name}`);
|
||||
let localPath = join(storePath, file.id[0], `${file.id}_${file.name}`);
|
||||
let remotePath = join(file.id[0], `${file.id}_${file.name}`);
|
||||
if (this.params.size > 0) {
|
||||
localPath = join(storePath, file._id[0], this.params.size, `${file._id}_${file.file_name}`);
|
||||
remotePath = join(file._id[0], this.params.size, `${file._id}_${file.file_name}`);
|
||||
localPath = join(storePath, file.id[0], this.params.size, `${file.id}_${file.name}`);
|
||||
remotePath = join(file.id[0], this.params.size, `${file.id}_${file.name}`);
|
||||
}
|
||||
|
||||
if (file.malware) {
|
||||
|
@ -73,13 +76,13 @@ export function* get() {
|
|||
if (this.params.size) {
|
||||
this.statsd.incr('file.view', 1);
|
||||
}
|
||||
type = mime.lookup(file.file_name);
|
||||
type = mime.lookup(file.name);
|
||||
} else {
|
||||
this.statsd.incr('file.download', 1);
|
||||
}
|
||||
|
||||
if (userAgentCheck(this.headers['user-agent'])) {
|
||||
this.set('Content-Disposition', `attachment; filename=${file.file_name}`);
|
||||
this.set('Content-Disposition', `attachment; filename=${file.name}`);
|
||||
}
|
||||
|
||||
this.set('Content-type', type);
|
||||
|
@ -87,10 +90,7 @@ export function* get() {
|
|||
this.set('Cache-control', 'max-age=2592000');
|
||||
|
||||
if (!this.params.size || (this.params.size && this.params.size > 150)) {
|
||||
this.db.Files.updateOne(
|
||||
{ _id: file._id },
|
||||
{ $set: { last_accessed: Math.ceil(Date.now() / 1000) }, $inc: { downloads: 1 } },
|
||||
{ w: 0 });
|
||||
models.file.accessed(file.id);
|
||||
}
|
||||
|
||||
this.body = yield hostrFileStream(localPath, remotePath);
|
||||
|
@ -101,10 +101,15 @@ export function* resized() {
|
|||
}
|
||||
|
||||
export function* landing() {
|
||||
const file = yield this.db.Files.findOne({ _id: this.params.id, status: 'active' });
|
||||
const file = yield models.file.findOne({
|
||||
where: {
|
||||
id: this.params.id,
|
||||
status: 'active',
|
||||
},
|
||||
});
|
||||
this.assert(file, 404);
|
||||
if (userAgentCheck(this.headers['user-agent'])) {
|
||||
this.params.name = file.file_name;
|
||||
this.params.name = file.name;
|
||||
yield get.call(this);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue