- 下記のスクリプトを記述した XML ファイルをダウンロードできます
- box-file-delete.xml (C) Questetra, Inc. (MIT License)
- Professional をご利用であればファイルの内容を改変することでオリジナルのアドオンとして活用できます
main();
function main(){
const fileIds = engine.findDataByNumber(configs.get("conf_FileIds"));
if (fileIds === "" ||fileIds === null){
throw "File IDs aren't set.";
}
let linesArray = fileIds.split("\n");
linesArray = linesArray.filter(lines => lines !== ""); // 空文字列を削除
if (linesArray.length === 0) {
throw "File IDs aren't set.";
}
const numOfLines = linesArray.length;
if (numOfLines > httpClient.getRequestingLimit()){
throw "Number of File IDs is over the limit."
}
const oauth2 = configs.get("conf_OAuth2");
for (let i = 0; i < numOfLines; i++){
deleteFile(oauth2, linesArray[i])
}
}
function deleteFile(oauth2, fileId) {
const url = `https://api.box.com/2.0/files/${fileId}`;
const response = httpClient.begin()
.authSetting(oauth2)
.delete(url);
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
engine.log(`status: ${status}`);
if (status >= 300) {
engine.log(responseTxt)
throw `Failed to delete File ID:${fileId}`;
}else{
engine.log(`Succeeded to delete File ID:${fileId}`);
}
}