firefox, chrome, safari, edge all working, pr changes included
This commit is contained in:
parent
fdb0734208
commit
6cb1fc433e
8 changed files with 634 additions and 46 deletions
|
@ -32,4 +32,10 @@ let conf = convict({
|
|||
// Perform validation
|
||||
conf.validate({ allowed: 'strict' });
|
||||
|
||||
module.exports = conf.getProperties();
|
||||
let props = conf.getProperties();
|
||||
module.exports = props;
|
||||
|
||||
module.exports.notLocalHost =
|
||||
props.env === 'production' &&
|
||||
props.s3_bucket !== 'localhost' &&
|
||||
props.bitly_key !== 'localhost';
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
const conf = require('./config.js');
|
||||
|
||||
let notLocalHost =
|
||||
conf.env === 'production' &&
|
||||
conf.s3_bucket !== 'localhost' &&
|
||||
conf.bitly_key !== 'localhost';
|
||||
let notLocalHost = conf.notLocalHost;
|
||||
|
||||
const mozlog = require('mozlog') ({
|
||||
app: 'FirefoxFileshare',
|
||||
|
|
|
@ -11,10 +11,7 @@ const bytes = require('bytes');
|
|||
const conf = require('./config.js');
|
||||
const storage = require('./storage.js');
|
||||
|
||||
let notLocalHost =
|
||||
conf.env === 'production' &&
|
||||
conf.s3_bucket !== 'localhost' &&
|
||||
conf.bitly_key !== 'localhost';
|
||||
let notLocalHost = conf.notLocalHost;
|
||||
|
||||
const mozlog = require('./log.js');
|
||||
|
||||
|
@ -74,19 +71,18 @@ app.get('/assets/download/:id', (req, res) => {
|
|||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Length': contentLength
|
||||
});
|
||||
});
|
||||
let file_stream = storage.get(id);
|
||||
|
||||
let file_stream = storage.get(id);
|
||||
|
||||
file_stream.on(notLocalHost ? 'finish' : 'close', () => {
|
||||
storage.forceDelete(id).then(err => {
|
||||
if (!err) {
|
||||
log.info('Deleted:', id);
|
||||
}
|
||||
file_stream.on(notLocalHost ? 'finish' : 'close', () => {
|
||||
storage.forceDelete(id).then(err => {
|
||||
if (!err) {
|
||||
log.info('Deleted:', id);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
file_stream.pipe(res);
|
||||
file_stream.pipe(res);
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.sendStatus(404);
|
||||
|
@ -127,7 +123,7 @@ app.post('/upload/:id', (req, res, next) => {
|
|||
req.busboy.on('file', (fieldname, file, filename) => {
|
||||
log.info('Uploading:', req.params.id);
|
||||
|
||||
const protocol = !notLocalHost ? req.protocol : 'https';
|
||||
const protocol = notLocalHost ? 'https' : req.protocol;
|
||||
let url = `${protocol}://${req.get('host')}/download/${req.params.id}/`;
|
||||
|
||||
storage.set(req.params.id, file, filename, url).then(linkAndID => {
|
||||
|
|
|
@ -8,10 +8,7 @@ const fetch = require('node-fetch');
|
|||
const crypto = require('crypto');
|
||||
|
||||
|
||||
let notLocalHost =
|
||||
conf.env === 'production' &&
|
||||
conf.s3_bucket !== 'localhost' &&
|
||||
conf.bitly_key !== 'localhost';
|
||||
let notLocalHost = conf.notLocalHost;
|
||||
|
||||
const mozlog = require('./log.js');
|
||||
|
||||
|
@ -27,27 +24,25 @@ redis_client.on('error', err => {
|
|||
log.info('Redis: ', err);
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (notLocalHost) {
|
||||
module.exports = {
|
||||
filename: filename,
|
||||
exists: exists,
|
||||
length: awsLength,
|
||||
get: awsGet,
|
||||
set: awsSet,
|
||||
delete: awsDelete,
|
||||
forceDelete: awsForceDelete,
|
||||
exists: awsExists
|
||||
forceDelete: awsForceDelete
|
||||
};
|
||||
} else {
|
||||
module.exports = {
|
||||
filename: filename,
|
||||
exists: exists,
|
||||
length: localLength,
|
||||
get: localGet,
|
||||
set: localSet,
|
||||
delete: localDelete,
|
||||
forceDelete: localForceDelete,
|
||||
exists: localExists
|
||||
forceDelete: localForceDelete
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -63,10 +58,10 @@ function filename(id) {
|
|||
});
|
||||
}
|
||||
|
||||
function localExists(id) {
|
||||
function exists(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
redis_client.hget(id, 'filename', (rediserr, reply) => {
|
||||
resolve(fs.existsSync(__dirname + '/../static/' + id) && !rediserr)
|
||||
redis_client.exists(id, (rediserr, reply) => {
|
||||
resolve(reply === 1)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -125,16 +120,6 @@ function localForceDelete(id) {
|
|||
});
|
||||
}
|
||||
|
||||
function awsExists(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
s3.getObject(params, function(awserr, data) {
|
||||
redis_client.hget(id, 'filename', (rediserr, reply) => {
|
||||
resolve(!awserr && !rediserr);
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function awsLength(id) {
|
||||
let params = {
|
||||
Bucket: conf.s3_bucket,
|
||||
|
@ -178,7 +163,7 @@ function awsSet(id, file, filename, url) {
|
|||
redis_client.hmset([id, 'filename', filename, 'delete', uuid]);
|
||||
|
||||
redis_client.expire(id, 86400000);
|
||||
log('awsUploadFinish', 'Upload Finished of ' + filename);
|
||||
log.info('awsUploadFinish', 'Upload Finished of ' + filename);
|
||||
if (conf.bitly_key) {
|
||||
fetch(
|
||||
'https://api-ssl.bitly.com/v3/shorten?access_token=' +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue