mirror of
https://github.com/rexlManu/pterodactyl-upload-action.git
synced 2025-02-03 13:36:41 -05:00
Merge pull request #1 from t3rry327/add_decompress_feature
Add decompress feature
This commit is contained in:
commit
ba8dcf44b4
2 changed files with 29 additions and 2 deletions
|
@ -46,7 +46,11 @@ jobs:
|
|||
# hello.txt
|
||||
# hello2.txt
|
||||
target: "./"
|
||||
# decompress-target: true
|
||||
```
|
||||
## File Decompression
|
||||
|
||||
`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.
|
||||
|
||||
### Multiple File/Server Example
|
||||
|
||||
|
|
27
src/index.js
27
src/index.js
|
@ -10,8 +10,8 @@ async function main() {
|
|||
const settings = await getSettings();
|
||||
configureAxios(settings.panelHost, settings.apiKey, settings.proxy);
|
||||
|
||||
const { serverIds, sourceListPath, targetPath, restart, targets } =
|
||||
settings;
|
||||
const { serverIds, sourceListPath, targetPath, restart, targets, decompressTarget } =
|
||||
settings;
|
||||
|
||||
for (const serverId of serverIds) {
|
||||
for (const source of sourceListPath) {
|
||||
|
@ -20,7 +20,12 @@ async function main() {
|
|||
const buffer = await fs.readFile(source);
|
||||
|
||||
await uploadFile(serverId, targetFile, buffer);
|
||||
|
||||
if (decompressTarget && isArchiveFile(targetFile)) {
|
||||
await decompressFile(serverId, targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
for (const element of targets) {
|
||||
const { source, target } = element;
|
||||
await validateSourceFile(source);
|
||||
|
@ -28,6 +33,10 @@ async function main() {
|
|||
const buffer = await fs.readFile(source);
|
||||
|
||||
await uploadFile(serverId, targetFile, buffer);
|
||||
|
||||
if (decompressTarget && isArchiveFile(targetFile)) {
|
||||
await decompressFile(serverId, targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (restart) await restartServer(serverId);
|
||||
|
@ -44,6 +53,7 @@ async function getSettings() {
|
|||
const apiKey = getInput("api-key", { required: true });
|
||||
const restart = getInput("restart") == "true";
|
||||
const proxy = getInput("proxy");
|
||||
const decompressTarget = getInput("decompress-target") == "true";
|
||||
|
||||
let sourcePath = getInput("source");
|
||||
let sourceListPath = getMultilineInput("sources");
|
||||
|
@ -106,6 +116,7 @@ async function getSettings() {
|
|||
targetPath,
|
||||
serverIds,
|
||||
targets,
|
||||
decompressTarget,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -137,6 +148,11 @@ async function validateSourceFile(source) {
|
|||
}
|
||||
}
|
||||
|
||||
function isArchiveFile(fileName) {
|
||||
const ext = path.extname(fileName).toLowerCase();
|
||||
return ['.zip', '.tar', '.tar.gz', '.tgz', '.rar'].includes(ext);
|
||||
}
|
||||
|
||||
function getTargetFile(targetPath, source) {
|
||||
return targetPath.endsWith("/")
|
||||
? path.join(targetPath, path.basename(source))
|
||||
|
@ -163,6 +179,13 @@ async function restartServer(serverId) {
|
|||
});
|
||||
}
|
||||
|
||||
async function decompressFile(serverId, targetFile) {
|
||||
await axios.post(`/api/client/servers/${serverId}/files/decompress`, {
|
||||
root: "/",
|
||||
file: targetFile,
|
||||
});
|
||||
}
|
||||
|
||||
function getInput(name, options = { required: false }) {
|
||||
return core.getInput(name, { ...options, trimWhitespace: true });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue