Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/apps/user/appstore/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,20 @@ export class AppStoreRuntime extends AppProcess {
this.pid
);

const result = await this.distrib.publishing_updateStoreItemFromPath(pkg._id, path, (progress) => {
const updateResult = await this.distrib.publishing_updateStoreItemFromPath(pkg._id, path, (progress) => {
prog.show();
prog.setMax(progress.max + 1);
prog.setDone(progress.value);
if (progress.what) prog.updSub(progress.what);
});

if (!result) {
prog.stop();

if (!updateResult.success) {
MessageBox(
{
title: "Failed to update store item",
message:
"The server didn't accept your update package. Maybe its format is incorrect, the app ID differs, or the version isn't increased. Please check the package and try again.",
message: `The server didn't accept your update package. Maybe its format is incorrect, the app ID differs, or the version isn't increased. Please check the package and try again.<br><br>Details: ${updateResult.errorMessage ?? "Unknown error"}`,
buttons: [{ caption: "Okay", action: () => {}, suggested: true }],
image: "ErrorIcon",
sound: "arcos.dialog.error",
Expand All @@ -356,8 +357,6 @@ export class AppStoreRuntime extends AppProcess {
}

await this.switchPage("manageStoreItem", { id: pkg._id }, true);

prog.stop();
}

readmeFallback(pkg: StoreItem): string {
Expand Down
3 changes: 2 additions & 1 deletion src/css/apps/core/loginapp.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ div.window#loginApp > div.body div.login-form button.continue:active span.lucide
}
div.window#loginApp > div.body p.error-message {
font-size: 16px;
max-width: 600px;
max-width: 550px;
width: fit-content;
text-align: center;
}

Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/services/DistribSvc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Constructs } from "$interfaces/common";
import type { IInstallerProcessBase } from "$interfaces/distrib";
import type { ICommandResult } from "$interfaces/result";
import type { IBaseService } from "$interfaces/service";
import type { FilesystemProgressCallback } from "$types/fs";
import type { UpdateWriteOpResult } from "$types/mongo";
import type { ArcPackage, PartialStoreItem, StoreItem, UpdateInfo } from "$types/package";
import type { UserPreferencesStore } from "$types/user";
import type JSZip from "jszip";
Expand Down Expand Up @@ -60,5 +62,5 @@ export interface IDistributionServiceProcess extends IBaseService {
itemId: string,
updatePath: string,
onProgress?: FilesystemProgressCallback
): Promise<boolean>;
}
): Promise<ICommandResult<UpdateWriteOpResult>>;
}
9 changes: 2 additions & 7 deletions src/ts/daemon/contexts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import type { IUserDaemon } from "$interfaces/daemon";
import DeleteUser from "$lib/Daemon/DeleteUser.svelte";
import { Env, Server, SysDispatch } from "$ts/env";
import { Backend } from "$ts/kernel/mods/server/axios";
import { CommandResult } from "$ts/result";
import { authcode } from "$ts/util";
import { MessageBox } from "$ts/util/dialog";
import { toForm } from "$ts/util/form";
import { ElevationLevel } from "$types/elevation";
import { LogLevel } from "$types/logging";
import type { PublicUserInfo, UserInfo } from "$types/user";
import Cookies from "js-cookie";
import { Daemon } from "..";
import { UserContext } from "../context";
import { CommandResult } from "$ts/result";
import { AxiosError } from "axios";

export class AccountUserContext extends UserContext implements IAccountUserContext {
constructor(id: string, daemon: IUserDaemon) {
Expand Down Expand Up @@ -69,10 +67,7 @@ export class AccountUserContext extends UserContext implements IAccountUserConte
return CommandResult.Ok(response.data as UserInfo);
} catch (e) {
await Daemon!.killSelf();

const error = (e instanceof AxiosError ? e?.response?.data?.e : `${e}`) || `Unknown error`;

return CommandResult.Error(error);
return CommandResult.AxiosError(e, "Unknown error while obtaining user information. Please try again.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ts/kernel/mods/fs/drives/src.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class SourceFilesystemDrive extends FilesystemDrive {

return CommandResult.Ok<ArrayBuffer>(response.data);
} catch (e) {
return CommandResult.Error(`Failed to read file: ${e}`);
return CommandResult.AxiosError(e);
}
}

Expand All @@ -69,7 +69,7 @@ export class SourceFilesystemDrive extends FilesystemDrive {

return CommandResult.Ok<GitFolder>(response.data);
} catch (e) {
return CommandResult.Error(`Failed to read folder: ${e}`);
return CommandResult.AxiosError(e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ts/kernel/mods/fs/proxies/src.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SourceFilesystemProxy extends FilesystemProxy {

return CommandResult.Ok<ArrayBuffer>(response.data);
} catch (e) {
return CommandResult.Error(`Failed to read file: ${e}`);
return CommandResult.AxiosError(e);
}
}

Expand All @@ -41,7 +41,7 @@ export class SourceFilesystemProxy extends FilesystemProxy {

return CommandResult.Ok<GitFolder>(response.data);
} catch (e) {
return CommandResult.Error(`Failed to read folder: ${e}`);
return CommandResult.AxiosError(e);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/ts/result.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ICommandResult } from "$interfaces/result";
import { DefaultCommandResultOptions, type CommandResultOptions } from "$types/result";
import { AxiosError } from "axios";
import { Log } from "./logging";

export class CommandResult<T = string> implements ICommandResult<T> {
Expand Down Expand Up @@ -27,4 +28,8 @@ export class CommandResult<T = string> implements ICommandResult<T> {

return new this<T>(undefined, { errorMessage });
}

static AxiosError<T = any>(e: unknown, fallback: string = "Unknown error") {
return new this<T>(undefined, { errorMessage: (e instanceof AxiosError ? e.response?.data?.e : `${e || ""}`) || fallback });
}
}
20 changes: 14 additions & 6 deletions src/ts/servicehost/services/DistribSvc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IDistributionServiceProcess } from "$interfaces/services/DistribSv
import { Daemon } from "$ts/daemon";
import { Fs, Stack } from "$ts/env";
import { Backend } from "$ts/kernel/mods/server/axios";
import { CommandResult } from "$ts/result";
import type { ServiceHost } from "$ts/servicehost";
import { BaseService } from "$ts/servicehost/base";
import { UserPaths } from "$ts/user/store";
Expand All @@ -11,6 +12,7 @@ import { join } from "$ts/util/fs";
import { tryJsonParse } from "$ts/util/json";
import { compareVersion } from "$ts/util/version";
import type { FilesystemProgressCallback } from "$types/fs";
import type { UpdateWriteOpResult } from "$types/mongo";
import type { ArcPackage, PartialStoreItem, StoreItem, UpdateInfo } from "$types/package";
import type { Service } from "$types/service";
import type { UserPreferencesStore } from "$types/user";
Expand Down Expand Up @@ -670,17 +672,21 @@ export class DistributionServiceProcess extends BaseService implements IDistribu
}
}

async publishing_updateStoreItemFromPath(itemId: string, updatePath: string, onProgress?: FilesystemProgressCallback) {
async publishing_updateStoreItemFromPath(
itemId: string,
updatePath: string,
onProgress?: FilesystemProgressCallback
): Promise<CommandResult<UpdateWriteOpResult>> {
this.Log(`publishing_updateStoreItemFromPath: ${itemId} -> ${updatePath}`);

if (this.checkBusy("publishing_updateStoreItemFromPath")) return false;
if (this.checkBusy("publishing_updateStoreItemFromPath")) return CommandResult.Error("Distribution Service is busy");

try {
const contents = await Fs.readFile(updatePath, (p) => {
onProgress?.({ ...p, what: "Loading update package" });
});

if (!contents) return false;
if (!contents) return CommandResult.Error("Failed to read the update file");

const newData = arrayBufferToBlob(contents);
const response = await Backend.patch(`/store/publish/${itemId}`, newData, {
Expand All @@ -695,9 +701,11 @@ export class DistributionServiceProcess extends BaseService implements IDistribu
},
});

return response.status === 200;
} catch {
return false;
if (response.status !== 200) return CommandResult.AxiosError(response.data?.e ?? "Unknown error");

return CommandResult.Ok<UpdateWriteOpResult>(response.data);
} catch (e) {
return CommandResult.AxiosError(e);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/ts/user/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export async function LoginUser(identity: string, password: string): Promise<Com

return CommandResult.Ok(response.data.token);
} catch (e) {
const err = e as AxiosError;

Log("LoginUser", "API request errored:\n" + err, LogLevel.error);
Log("LoginUser", "API request errored:\n" + e, LogLevel.error);

return CommandResult.Error(err instanceof AxiosError ? (err.response?.data as any)?.e : `${e}` || "Unknown Message");
return CommandResult.AxiosError(
e,
"An unknown error occurred. Please check your credentials, and then try again. If the problem persists, please contact an ArcOS administrator."
);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/types/mongo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface UpdateResult {
acknowledged: boolean;
matchedCount: number;
modifiedCount: number;
upsertedCount: number;
upsertedId: number;
}

export declare interface DeleteResult {
acknowledged: boolean;
deletedCount: number;
}

export type UpdateWriteOpResult = UpdateResult;