feat: delete file after decompression

This commit is contained in:
Emmanuel Lampe 2023-08-22 17:38:45 +02:00
parent cc232ce884
commit f65b7500c8
No known key found for this signature in database
GPG key ID: 2E080FC227CB0AE7
2 changed files with 20 additions and 3 deletions

View file

@ -56,6 +56,8 @@ jobs:
`decompress-target` allows decompression of archive files (`.zip, .tar, .tar.gz, .tgz, .rar`) after they are uploaded to the server. If you have multiple targets, it will decompress all valid compressed ones. If this option is not provided or set to false, files will be uploaded as is, without decompression.
The archive will be deleted after decompression.
### Multiple File/Server Example
Uncomment lines for `server-ids`, `sources`, and `proxy` in the above example as necessary.

View file

@ -10,8 +10,14 @@ async function main() {
const settings = await getSettings();
configureAxios(settings.panelHost, settings.apiKey, settings.proxy);
const { serverIds, sourceListPath, targetPath, restart, targets, decompressTarget } =
settings;
const {
serverIds,
sourceListPath,
targetPath,
restart,
targets,
decompressTarget,
} = settings;
for (const serverId of serverIds) {
for (const source of sourceListPath) {
@ -23,6 +29,7 @@ async function main() {
if (decompressTarget && isArchiveFile(targetFile)) {
await decompressFile(serverId, targetFile);
await deleteFile(serverId, targetFile);
}
}
@ -36,6 +43,7 @@ async function main() {
if (decompressTarget && isArchiveFile(targetFile)) {
await decompressFile(serverId, targetFile);
await deleteFile(serverId, targetFile);
}
}
@ -150,7 +158,7 @@ async function validateSourceFile(source) {
function isArchiveFile(fileName) {
const ext = path.extname(fileName).toLowerCase();
return ['.zip', '.tar', '.tar.gz', '.tgz', '.rar'].includes(ext);
return [".zip", ".tar", ".tar.gz", ".tgz", ".rar"].includes(ext);
}
function getTargetFile(targetPath, source) {
@ -186,6 +194,13 @@ async function decompressFile(serverId, targetFile) {
});
}
async function deleteFile(serverId, targetFile) {
await axios.post(`/api/client/servers/${serverId}/files/delete`, {
root: "/",
files: [targetFile],
});
}
function getInput(name, options = { required: false }) {
return core.getInput(name, { ...options, trimWhitespace: true });
}