зеркало из https://github.com/mozilla/send.git
set the mime type in the download blob
This commit is contained in:
Родитель
626e578acb
Коммит
193664a8e8
|
@ -57,7 +57,8 @@ function download() {
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
})
|
})
|
||||||
.then(([decrypted, fname]) => {
|
.then(([decrypted, file]) => {
|
||||||
|
const fname = file.name;
|
||||||
const endTime = Date.now();
|
const endTime = Date.now();
|
||||||
const time = endTime - startTime;
|
const time = endTime - startTime;
|
||||||
const downloadTime = endTime - downloadEnd;
|
const downloadTime = endTime - downloadEnd;
|
||||||
|
@ -73,7 +74,7 @@ function download() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const dataView = new DataView(decrypted);
|
const dataView = new DataView(decrypted);
|
||||||
const blob = new Blob([dataView]);
|
const blob = new Blob([dataView], { type: file.type });
|
||||||
const downloadUrl = URL.createObjectURL(blob);
|
const downloadUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
|
|
|
@ -39,13 +39,15 @@ class FileReceiver extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
const blob = new Blob([this.response]);
|
const blob = new Blob([this.response]);
|
||||||
|
const type = xhr.getResponseHeader('Content-Type');
|
||||||
|
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
|
||||||
const fileReader = new FileReader();
|
const fileReader = new FileReader();
|
||||||
fileReader.onload = function() {
|
fileReader.onload = function() {
|
||||||
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
|
|
||||||
resolve([
|
resolve([
|
||||||
{
|
{
|
||||||
data: this.result,
|
data: this.result,
|
||||||
filename: meta.filename,
|
filename: meta.filename,
|
||||||
|
type,
|
||||||
iv: meta.id
|
iv: meta.id
|
||||||
},
|
},
|
||||||
key
|
key
|
||||||
|
@ -76,7 +78,10 @@ class FileReceiver extends EventEmitter {
|
||||||
.then(decrypted => {
|
.then(decrypted => {
|
||||||
return Promise.resolve(decrypted);
|
return Promise.resolve(decrypted);
|
||||||
}),
|
}),
|
||||||
decodeURIComponent(fdata.filename)
|
{
|
||||||
|
name: decodeURIComponent(fdata.filename),
|
||||||
|
type: fdata.type
|
||||||
|
}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ app.get('/assets/download/:id', async (req, res) => {
|
||||||
const contentLength = await storage.length(id);
|
const contentLength = await storage.length(id);
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Disposition': `attachment; filename=${meta.filename}`,
|
'Content-Disposition': `attachment; filename=${meta.filename}`,
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': meta.mimeType,
|
||||||
'Content-Length': contentLength,
|
'Content-Length': contentLength,
|
||||||
'X-File-Metadata': JSON.stringify(meta)
|
'X-File-Metadata': JSON.stringify(meta)
|
||||||
});
|
});
|
||||||
|
@ -236,24 +236,27 @@ app.post('/upload', (req, res, next) => {
|
||||||
meta.delete = crypto.randomBytes(10).toString('hex');
|
meta.delete = crypto.randomBytes(10).toString('hex');
|
||||||
req.pipe(req.busboy);
|
req.pipe(req.busboy);
|
||||||
|
|
||||||
req.busboy.on('file', async (fieldname, file, filename) => {
|
req.busboy.on(
|
||||||
try {
|
'file',
|
||||||
await storage.set(newId, file, filename, meta);
|
async (fieldname, file, filename, encoding, mimeType) => {
|
||||||
|
try {
|
||||||
const protocol = conf.env === 'production' ? 'https' : req.protocol;
|
meta.mimeType = mimeType || 'application/octet-stream';
|
||||||
const url = `${protocol}://${req.get('host')}/download/${newId}/`;
|
await storage.set(newId, file, filename, meta);
|
||||||
res.json({
|
const protocol = conf.env === 'production' ? 'https' : req.protocol;
|
||||||
url,
|
const url = `${protocol}://${req.get('host')}/download/${newId}/`;
|
||||||
delete: meta.delete,
|
res.json({
|
||||||
id: newId
|
url,
|
||||||
});
|
delete: meta.delete,
|
||||||
} catch (e) {
|
id: newId
|
||||||
if (e.message === 'limit') {
|
});
|
||||||
return res.sendStatus(413);
|
} catch (e) {
|
||||||
|
if (e.message === 'limit') {
|
||||||
|
return res.sendStatus(413);
|
||||||
|
}
|
||||||
|
res.sendStatus(500);
|
||||||
}
|
}
|
||||||
res.sendStatus(500);
|
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
req.on('close', async err => {
|
req.on('close', async err => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -163,7 +163,7 @@ describe('Server integration tests', function() {
|
||||||
res.header['content-disposition'],
|
res.header['content-disposition'],
|
||||||
'attachment; filename=test_upload.txt'
|
'attachment; filename=test_upload.txt'
|
||||||
);
|
);
|
||||||
assert.equal(res.header['content-type'], 'application/octet-stream');
|
assert.equal(res.header['content-type'], 'text/plain');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,15 @@ module.exports = {
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
loaders: 'babel-loader',
|
loaders: 'babel-loader',
|
||||||
include: [path.resolve(__dirname, 'frontend'), path.resolve(__dirname, 'node_modules/testpilot-ga/src')],
|
include: [
|
||||||
query: { babelrc: false, presets: ['es2015', 'stage-2'], plugins: ['add-module-exports'] }
|
path.resolve(__dirname, 'frontend'),
|
||||||
|
path.resolve(__dirname, 'node_modules/testpilot-ga/src')
|
||||||
|
],
|
||||||
|
query: {
|
||||||
|
babelrc: false,
|
||||||
|
presets: ['es2015', 'stage-2'],
|
||||||
|
plugins: ['add-module-exports']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче