mirror of
https://github.com/rexlManu/pterodactyl-upload-action.git
synced 2025-02-03 21:46:40 -05:00
refactor: Add targets to settings and upload targets
This commit is contained in:
parent
19601e8881
commit
c5ce58738f
1 changed files with 21 additions and 5 deletions
26
src/index.js
26
src/index.js
|
@ -10,7 +10,8 @@ async function main() {
|
|||
const settings = await getSettings();
|
||||
configureAxios(settings.panelHost, settings.apiKey, settings.proxy);
|
||||
|
||||
const { serverIds, sourceListPath, targetPath, restart } = settings;
|
||||
const { serverIds, sourceListPath, targetPath, restart, targets } =
|
||||
settings;
|
||||
|
||||
for (const serverId of serverIds) {
|
||||
for (const source of sourceListPath) {
|
||||
|
@ -19,9 +20,17 @@ async function main() {
|
|||
const buffer = await fs.readFile(source);
|
||||
|
||||
await uploadFile(serverId, targetFile, buffer);
|
||||
|
||||
if (restart) await restartServer(serverId);
|
||||
}
|
||||
for (const element of targets) {
|
||||
const { source, target } = element;
|
||||
await validateSourceFile(source);
|
||||
const targetFile = getTargetFile(target, source);
|
||||
const buffer = await fs.readFile(source);
|
||||
|
||||
await uploadFile(serverId, targetFile, buffer);
|
||||
}
|
||||
|
||||
if (restart) await restartServer(serverId);
|
||||
}
|
||||
|
||||
core.info("Done");
|
||||
|
@ -38,7 +47,7 @@ async function getSettings() {
|
|||
|
||||
let sourcePath = getInput("source");
|
||||
let sourceListPath = getMultilineInput("sources");
|
||||
let targetPath = getInput("target", { required: true });
|
||||
let targetPath = getInput("target");
|
||||
let serverIdInput = getInput("server-id");
|
||||
let serverIds = getMultilineInput("server-ids");
|
||||
|
||||
|
@ -60,6 +69,8 @@ async function getSettings() {
|
|||
serverIdInput = serverIdInput || config.server || "";
|
||||
serverIds = serverIds.length ? serverIds : config.servers || [];
|
||||
|
||||
const targets = config.targets || [];
|
||||
|
||||
// Debug print out all the config
|
||||
core.debug(`config: ${JSON.stringify(config)}`);
|
||||
|
||||
|
@ -70,7 +81,11 @@ async function getSettings() {
|
|||
core.debug(`server-id: ${serverIdInput}`);
|
||||
core.debug(`server-ids: ${serverIds}`);
|
||||
|
||||
if (!sourcePath && !sourceListPath.length)
|
||||
if (
|
||||
!sourcePath &&
|
||||
!sourceListPath.length &&
|
||||
(!targets.length || targets.length == 0)
|
||||
)
|
||||
throw new Error(
|
||||
"Either source or sources must be defined. Both are empty."
|
||||
);
|
||||
|
@ -90,6 +105,7 @@ async function getSettings() {
|
|||
sourceListPath,
|
||||
targetPath,
|
||||
serverIds,
|
||||
targets,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue