ken_nogi/pleasanter/develop2/四者MTG回覧板システム/scripts/02_ファイルまとめてDL.js
Kenichiro NOGI 88a402ce0f up
2026-07-10 18:13:30 +09:00

64 lines
1.7 KiB
JavaScript

function dlAllFiles(zipFilename) {
let guidListString = $('#Results_Description001').val();
let guidList = [];
if (guidListString.length > 0) {
guidList = guidListString.split(',');
} else {
return;
}
if (guidList.length > 0) {
dlZipAttachements(guidList, zipFilename);
}
}
/**
* 複数ファイルを1ファイルにzip圧縮してDLする
* @param guidList DLする添付ファイルのGUIDのリスト
* @param zipFilename zipファイル名
* @return なし
*/
async function dlZipAttachements(guidList, zipFilename) {
var binary;
var filename;
const zip = new JSZip();
const jsonReq = {
'ApiVersion': 1.1,
'ApiKey': apiKey,
};
for (guid of guidList) {
await axios.post("/pleasanter/api/binaries/" + guid + "/get", jsonReq)
.then(function (response) {
binary = decodeBase64(response.data.Response.Base64);
filename = response.data.Response.FileName;
zip.folder(zipFilename).file(filename, binary, {
binary: true
});
})
.catch(function (error) {
console.log(error);
})
.finally(function () { });
}
saveAs(await zip.generateAsync({
type: "blob"
}), zipFilename + ".zip");
}
/**
* base64デコード処理
* @param base64 base64文字列
* @return デコードしたバイナリデータ
*/
function decodeBase64(base64) {
const bin = atob(base64.replace(/^.*,/, ''));
var buffer = new Uint8Array(bin.length);
for (var i = 0; i < bin.length; i++) {
buffer[i] = bin.charCodeAt(i);
}
return buffer.buffer;
}