You've already forked AstralRinth
forked from didirus/AstralRinth
Merge commit 'affeec82f0f868d7e8260896584497dd4ea6465f' into feature-clean
This commit is contained in:
@@ -272,6 +272,10 @@ const constructServerProperties = (properties: any): string => {
|
||||
|
||||
const processImage = async (iconUrl: string | undefined) => {
|
||||
const image = ref<string | null>(null);
|
||||
const sharedImage = useState<string | undefined>(
|
||||
`server-icon-${internalServerRefrence.value.serverId}`,
|
||||
() => undefined,
|
||||
);
|
||||
const auth = await PyroFetch<JWTAuth>(`servers/${internalServerRefrence.value.serverId}/fs`);
|
||||
try {
|
||||
const fileData = await PyroFetch(`/download?path=/server-icon-original.png`, {
|
||||
@@ -293,6 +297,7 @@ const processImage = async (iconUrl: string | undefined) => {
|
||||
const dataURL = canvas.toDataURL("image/png");
|
||||
internalServerRefrence.value.general.image = dataURL;
|
||||
image.value = dataURL;
|
||||
sharedImage.value = dataURL; // Store in useState
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
@@ -300,7 +305,7 @@ const processImage = async (iconUrl: string | undefined) => {
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof PyroFetchError && error.statusCode === 404) {
|
||||
console.log("[PYROSERVERS] No server icon found");
|
||||
sharedImage.value = undefined;
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
@@ -973,7 +978,6 @@ const modules: any = {
|
||||
suspend: suspendServer,
|
||||
getMotd,
|
||||
setMotd,
|
||||
fetchConfigFile,
|
||||
},
|
||||
content: {
|
||||
get: async (serverId: string) => {
|
||||
@@ -1131,8 +1135,7 @@ type GeneralFunctions = {
|
||||
setMotd: (motd: string) => Promise<void>;
|
||||
|
||||
/**
|
||||
* INTERNAL: Gets the config file of a server.
|
||||
* @param fileName - The name of the file.
|
||||
* @deprecated Use fs.downloadFile instead
|
||||
*/
|
||||
fetchConfigFile: (fileName: string) => Promise<any>;
|
||||
};
|
||||
@@ -1389,8 +1392,15 @@ export type Server<T extends avaliableModules> = {
|
||||
/**
|
||||
* Refreshes the included modules of the server
|
||||
* @param refreshModules - The modules to refresh.
|
||||
* @param options - The options to use when refreshing the modules.
|
||||
*/
|
||||
refresh: (refreshModules?: avaliableModules) => Promise<void>;
|
||||
refresh: (
|
||||
refreshModules?: avaliableModules,
|
||||
options?: {
|
||||
preserveConnection?: boolean;
|
||||
preserveInstallState?: boolean;
|
||||
},
|
||||
) => Promise<void>;
|
||||
setError: (error: Error) => void;
|
||||
error?: Error;
|
||||
serverId: string;
|
||||
@@ -1398,33 +1408,53 @@ export type Server<T extends avaliableModules> = {
|
||||
|
||||
export const usePyroServer = async (serverId: string, includedModules: avaliableModules) => {
|
||||
const server: Server<typeof includedModules> = reactive({
|
||||
refresh: async (refreshModules?: avaliableModules) => {
|
||||
refresh: async (
|
||||
refreshModules?: avaliableModules,
|
||||
options?: {
|
||||
preserveConnection?: boolean;
|
||||
preserveInstallState?: boolean;
|
||||
},
|
||||
) => {
|
||||
if (server.general?.status === "installing" && !refreshModules) {
|
||||
return;
|
||||
}
|
||||
|
||||
const modulesToRefresh = refreshModules || includedModules;
|
||||
const promises: Promise<void>[] = [];
|
||||
if (refreshModules) {
|
||||
for (const module of refreshModules) {
|
||||
|
||||
const uniqueModules = [...new Set(modulesToRefresh)];
|
||||
|
||||
for (const module of uniqueModules) {
|
||||
const mods = modules[module];
|
||||
if (mods.get) {
|
||||
promises.push(
|
||||
(async () => {
|
||||
const mods = modules[module];
|
||||
if (mods.get) {
|
||||
const data = await mods.get(serverId);
|
||||
server[module] = { ...server[module], ...data };
|
||||
}
|
||||
})(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for (const module of includedModules) {
|
||||
promises.push(
|
||||
(async () => {
|
||||
const mods = modules[module];
|
||||
if (mods.get) {
|
||||
const data = await mods.get(serverId);
|
||||
server[module] = { ...server[module], ...data };
|
||||
const data = await mods.get(serverId);
|
||||
if (data) {
|
||||
if (module === "general" && options?.preserveConnection) {
|
||||
const updatedData = {
|
||||
...server[module],
|
||||
...data,
|
||||
};
|
||||
if (server[module]?.image) {
|
||||
updatedData.image = server[module].image;
|
||||
}
|
||||
if (server[module]?.motd) {
|
||||
updatedData.motd = server[module].motd;
|
||||
}
|
||||
if (options.preserveInstallState && server[module]?.status === "installing") {
|
||||
updatedData.status = "installing";
|
||||
}
|
||||
server[module] = updatedData;
|
||||
} else {
|
||||
server[module] = { ...server[module], ...data };
|
||||
}
|
||||
}
|
||||
})(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
},
|
||||
setError: (error: Error) => {
|
||||
|
||||
Reference in New Issue
Block a user