mirror of
https://github.com/rexlManu/pterodactyl-upload-action.git
synced 2025-02-03 13:36:41 -05:00
feat: delete file after decompression
This commit is contained in:
parent
cc232ce884
commit
f65b7500c8
2 changed files with 20 additions and 3 deletions
|
@ -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.
|
||||
|
|
21
src/index.js
21
src/index.js
|
@ -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 });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue