Only store the fileId with b2.
It's smaller.
This commit is contained in:
parent
ff55ea0392
commit
ebb7c2d519
@ -46,6 +46,7 @@ const POSTRedirect = url => (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.post('/api/v1/get_upload_url', POSTRedirect('/b2api/v1/b2_get_upload_url'));
|
app.post('/api/v1/get_upload_url', POSTRedirect('/b2api/v1/b2_get_upload_url'));
|
||||||
|
app.post('/api/v1/get_file_info', POSTRedirect('/b2api/v1/b2_get_file_info'));
|
||||||
app.post('/api/v1/remove_file', POSTRedirect('/b2api/v1/b2_delete_file_version'));
|
app.post('/api/v1/remove_file', POSTRedirect('/b2api/v1/b2_delete_file_version'));
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -72,22 +72,25 @@ export const B2Adapter = function(b2apikey, b2secret, b2bucket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return PouchDBAttachmentProxy({
|
return PouchDBAttachmentProxy({
|
||||||
getFn: async function getAttachment(obj) {
|
getFn: async function getAttachment(id) {
|
||||||
const res = await fetch(await downloadUrl(obj.fileId), {
|
const res = await fetch(await downloadUrl(id), {
|
||||||
headers: await headers()
|
headers: await headers()
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.blob();
|
return res.blob();
|
||||||
},
|
},
|
||||||
remove: async function removeAttachment(obj) {
|
remove: async function removeAttachment(id) {
|
||||||
const s = await session();
|
const s = await session();
|
||||||
return fetch('/api/v1/remove_file', {
|
const res = await fetch('/api/v1/get_file_info', {
|
||||||
headers: await headers(),
|
headers: await headers(),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({ fileId: id })
|
||||||
fileName: obj.fileName,
|
});
|
||||||
fileId: obj.fileId
|
const { fileName, fileId } = await res.json();
|
||||||
})
|
return await fetch('/api/v1/remove_file', {
|
||||||
|
headers: await headers(),
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ fileName, fileId })
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
save: async function saveAttachment(blob) {
|
save: async function saveAttachment(blob) {
|
||||||
@ -104,11 +107,8 @@ export const B2Adapter = function(b2apikey, b2secret, b2bucket) {
|
|||||||
}),
|
}),
|
||||||
body: blob
|
body: blob
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const { fileId } = await res.json();
|
||||||
return {
|
return fileId;
|
||||||
fileId: data.fileId,
|
|
||||||
fileName: data.fileName
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user