Skip to content

Commit 9d0988e

Browse files
authored
publish latest features (#32)
1 parent d4f086e commit 9d0988e

27 files changed

+255
-53
lines changed

cli/src/run-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class RunManager {
292292
env: Record<string, string> = {},
293293
): Deno.ChildProcess {
294294
const cmd = new Deno.Command(Deno.execPath(), {
295-
args: ["run", "-A", ...flags, this.moduleName],
295+
args: ["run", "-A", ...flags, "--unstable-raw-imports", this.moduleName],
296296
cwd: this.rootPath,
297297
env: {
298298
CLOUD_RUNNER_MODE: mode,

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inspatial/cloud",
3-
"version": "0.5.9",
3+
"version": "0.6.0",
44
"license": "Apache-2.0",
55
"exports": {
66
".": "./mod.ts",

src/auth/auth-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class AuthHandler {
8080
if (!authToken) {
8181
return null;
8282
}
83-
let sessionData: SessionData = this.#inCloud.inCache.getValue(
83+
let sessionData: SessionData | undefined = this.#inCloud.inCache.getValue(
8484
"authToken",
8585
authToken,
8686
);

src/extension/core-extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { onboardingStep } from "../onboarding/ob-step.ts";
4141
import { onboardingSettings } from "../onboarding/ob-settings.ts";
4242
import { Currencies } from "../orm/field/field-def-types.ts";
4343
import { inLiveLifecycle } from "../in-live/in-live-lifecycle.ts";
44+
import { publicFilesHandler } from "../files/public-files-handler.ts";
4445
export const coreExtension = new CloudExtension("core", {
4546
description: "InSpatial Cloud Core Extension",
4647
label: "Core",
@@ -82,7 +83,7 @@ export const coreExtension = new CloudExtension("core", {
8283
onboardingStep,
8384
],
8485
middleware: [corsMiddleware, authMiddleware, inLiveMiddleware],
85-
pathHandlers: [apiPathHandler],
86+
pathHandlers: [apiPathHandler, publicFilesHandler],
8687
requestLifecycle: {
8788
setup: [authLifecycle, inLiveLifecycle],
8889
},

src/extension/settings/_system-settings.type.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ export interface SystemSettings extends SettingsBase {
88
* @type {boolean}
99
*/
1010
enableSignup?: boolean;
11+
/**
12+
* **Server Host** (URLField)
13+
* @description The host URL of the server. This is used for generating links and API endpoints.
14+
* @type {string}
15+
* @required true
16+
*/
17+
serverHost: string;
1118
}

src/extension/settings/systemSettings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export const systemSettings = new SettingsType<SystemSettings>(
1212
description:
1313
"Enable user signup for new accounts. Turn off to prevent new users from signing up.",
1414
defaultValue: true,
15+
}, {
16+
key: "serverHost",
17+
label: "Server Host",
18+
type: "URLField",
19+
description:
20+
"The host URL of the server. This is used for generating links and API endpoints.",
21+
defaultValue: "http://localhost:8000",
22+
required: true,
1523
}],
1624
},
1725
);

src/files/actions/get-file.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@ import { CloudAPIAction } from "~/api/cloud-action.ts";
22

33
import { raiseServerException } from "~/serve/server-exception.ts";
44
import type { CloudFile } from "../entries/_cloud-file.type.ts";
5+
import { GlobalCloudFile } from "../entries/_global-cloud-file.type.ts";
56

67
export const getFile = new CloudAPIAction("getFile", {
78
params: [{
89
key: "fileId",
910
label: "File ID",
1011
type: "DataField",
1112
required: true,
13+
}, {
14+
key: "global",
15+
label: "Global File",
16+
type: "BooleanField",
17+
description: "Whether the file is a global file",
1218
}, {
1319
key: "download",
1420
label: "Download",
1521
type: "BooleanField",
1622
}],
1723
async run({ orm, params, inResponse }) {
18-
const { fileId } = params;
19-
const file = await orm.getEntry<CloudFile>("cloudFile", fileId);
24+
const { fileId, global } = params;
25+
26+
const file = await orm.getEntry<CloudFile | GlobalCloudFile>(
27+
global ? "globalCloudFile" : "cloudFile",
28+
fileId,
29+
);
2030
try {
2131
const fileHandle = await Deno.open(file.filePath, { read: true });
2232

src/files/actions/upload-file.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,38 @@ import { CloudAPIAction } from "~/api/cloud-action.ts";
22
import type { CloudFile } from "../entries/_cloud-file.type.ts";
33
import MimeTypes from "../mime-types/mime-types.ts";
44
import { GlobalCloudFile } from "../entries/_global-cloud-file.type.ts";
5+
import { joinPath } from "@inspatial/cloud/utils";
56

67
export const uploadFile = new CloudAPIAction("upload", {
78
label: "Upload File",
89
raw: true,
910
params: [{
1011
key: "global",
1112
type: "BooleanField",
13+
}, {
14+
key: "publicFile",
15+
type: "BooleanField",
1216
}],
13-
async run({ inCloud, orm, inRequest, inResponse, params: { global } }) {
14-
console.log({ global });
17+
async run(
18+
{ inCloud, orm, inRequest, inResponse, params: { global, publicFile } },
19+
) {
1520
const formData = await inRequest.request.formData();
1621
const file = formData.get("content") as File;
1722
const fileName = formData.get("fileName") as string;
1823
let cloudFile: CloudFile | GlobalCloudFile;
24+
let accountId = orm._user!.accountId;
1925
switch (global) {
2026
case true:
2127
cloudFile = orm.getNewEntry<GlobalCloudFile>("globalCloudFile");
28+
accountId = "global";
2229
break;
2330
default:
2431
cloudFile = orm.getNewEntry<CloudFile>("cloudFile");
2532
}
26-
cloudFile = orm.getNewEntry<CloudFile>("cloudFile");
2733
cloudFile.fileName = fileName;
2834
cloudFile.fileSize = file.size;
2935
cloudFile.mimeType = file.type as any;
36+
cloudFile.publicFile = publicFile;
3037
const extensionInfo = MimeTypes.getExtensionsByMimeType(file.type);
3138
if (extensionInfo) {
3239
cloudFile.fileType = extensionInfo.category;
@@ -38,8 +45,17 @@ export const uploadFile = new CloudAPIAction("upload", {
3845
const id = cloudFile.id;
3946
const extension = fileName.split(".").pop();
4047
const newFileName = `${id}.${extension}`;
48+
4149
const stream = file.stream();
42-
const path = `${inCloud.filesPath}/${newFileName}`;
50+
let accountFolder = joinPath(inCloud.filesPath, accountId);
51+
let path = joinPath(accountFolder, newFileName);
52+
if (publicFile) {
53+
accountFolder = joinPath(inCloud.publicFilesPath, accountId);
54+
path = joinPath(accountFolder, newFileName);
55+
}
56+
await Deno.mkdir(accountFolder, {
57+
recursive: true,
58+
});
4359
await Deno.writeFile(path, stream, {
4460
create: true,
4561
});

src/files/entries/_cloud-file.type.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ export interface CloudFile extends EntryBase {
117117
* @required true
118118
*/
119119
filePath: string;
120+
/**
121+
* **Public File** (BooleanField)
122+
* @description If enabled, this file can be accessed publicly without authentication.
123+
* @type {boolean}
124+
*/
125+
publicFile?: boolean;
120126
/**
121127
* **File** (IDField)
122128
* @type {string}

src/files/entries/_global-cloud-file.type.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ export interface GlobalCloudFile extends EntryBase {
117117
* @required true
118118
*/
119119
filePath: string;
120+
/**
121+
* **Public File** (BooleanField)
122+
* @description If enabled, this file can be accessed publicly without authentication.
123+
* @type {boolean}
124+
*/
125+
publicFile?: boolean;
120126
/**
121127
* **System File** (IDField)
122128
* @type {string}

0 commit comments

Comments
 (0)