spec-3nweb-server 1.8.6 → 1.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/3nstorage/resources/store.d.ts +2 -2
- package/build/3nstorage/resources/store.js +1 -1
- package/build/3nstorage/resources/users.d.ts +3 -3
- package/build/3nstorage/resources/users.js +1 -1
- package/build/3nstorage/resources/utils.d.ts +6 -0
- package/build/3nstorage/resources/utils.js +41 -0
- package/build/3nstorage/routes/owner/archive-obj-version.js +8 -10
- package/build/3nstorage/routes/owner/cancel-trans.js +5 -4
- package/build/3nstorage/routes/owner/delete-obj.js +7 -8
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +11 -13
- package/build/3nstorage/routes/owner/get-current-obj.js +7 -6
- package/build/3nstorage/routes/owner/get-obj-status.js +8 -8
- package/build/3nstorage/routes/owner/put-current-obj.js +25 -55
- package/build/3nstorage/routes/owner/session-params.js +2 -0
- package/build/asmail/resources/utils.d.ts +6 -0
- package/build/asmail/resources/utils.js +36 -0
- package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
- package/build/asmail/routes/delivery/pre-flight.js +9 -26
- package/build/asmail/routes/delivery/provide-recipient-pubkey.js +4 -3
- package/build/asmail/routes/delivery/put-metadata.js +13 -21
- package/build/asmail/routes/delivery/put-obj.js +19 -25
- package/build/asmail/routes/delivery/restart-session.d.ts +4 -8
- package/build/asmail/routes/delivery/restart-session.js +10 -23
- package/build/asmail/routes/delivery/sender-authorization.js +5 -5
- package/build/asmail/routes/delivery/start-session.js +9 -24
- package/build/asmail/routes/retrieval/get-message-meta.js +4 -7
- package/build/asmail/routes/retrieval/get-message-obj.js +10 -7
- package/build/asmail/routes/retrieval/list-messages.js +4 -4
- package/build/asmail/routes/retrieval/remove-message.js +3 -2
- package/package.json +1 -1
- package/ts-code/3nstorage/resources/store.ts +3 -3
- package/ts-code/3nstorage/resources/users.ts +5 -5
- package/ts-code/3nstorage/resources/utils.ts +45 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +8 -10
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +5 -3
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +9 -13
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +13 -15
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +7 -5
- package/ts-code/3nstorage/routes/owner/get-obj-status.ts +8 -8
- package/ts-code/3nstorage/routes/owner/put-current-obj.ts +33 -60
- package/ts-code/3nstorage/routes/owner/session-params.ts +4 -3
- package/ts-code/asmail/resources/utils.ts +41 -0
- package/ts-code/asmail/routes/delivery/finalize-delivery.ts +3 -2
- package/ts-code/asmail/routes/delivery/pre-flight.ts +15 -29
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +4 -4
- package/ts-code/asmail/routes/delivery/put-metadata.ts +21 -30
- package/ts-code/asmail/routes/delivery/put-obj.ts +20 -34
- package/ts-code/asmail/routes/delivery/restart-session.ts +11 -24
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +5 -5
- package/ts-code/asmail/routes/delivery/start-session.ts +17 -32
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +5 -8
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +12 -15
- package/ts-code/asmail/routes/retrieval/list-messages.ts +4 -6
- package/ts-code/asmail/routes/retrieval/remove-message.ts +3 -2
|
@@ -113,7 +113,7 @@ export declare class Store extends UserFiles<StorageParams> {
|
|
|
113
113
|
* @return a promise, resolvable when version files are removed.
|
|
114
114
|
*/
|
|
115
115
|
private rmObjFiles;
|
|
116
|
-
archiveCurrentObjVersion(objId: string, version: number): Promise<void>;
|
|
117
|
-
getObjStatus(objId: string): Promise<ObjStatus>;
|
|
116
|
+
archiveCurrentObjVersion(objId: string | null, version: number): Promise<void>;
|
|
117
|
+
getObjStatus(objId: string | null): Promise<ObjStatus>;
|
|
118
118
|
setKeyDerivParams(params: any, setDefault: boolean): Promise<boolean>;
|
|
119
119
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2017, 2019 - 2020, 2022, 2025 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2017, 2019 - 2020, 2022, 2025 - 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -15,9 +15,9 @@ export type GetCurrentObj = (userId: string, objId: string | null, header: boole
|
|
|
15
15
|
}>;
|
|
16
16
|
export type SaveNewObjVersion = (userId: string, objId: string | null, fstReq: PutObjFirstQueryOpts | undefined, diff: DiffInfo | undefined, sndReq: PutObjSecondQueryOpts | undefined, bytesLen: number, bytes: ReadableStream) => Promise<string | undefined>;
|
|
17
17
|
export type GetArchivedObjVersion = (userId: string, objId: string | null, version: number, header: boolean, segsOffset: number, segsLimit: number | undefined) => Promise<ObjReader>;
|
|
18
|
-
export type CancelTransaction = (userId: string, objId: string, transactionId?: string) => Promise<void>;
|
|
19
|
-
export type ArchiveObjCurrentVersion = (userId: string, objId: string, version: number) => Promise<void>;
|
|
20
|
-
export type GetObjStatus = (userId: string, objId: string) => Promise<ObjStatus>;
|
|
18
|
+
export type CancelTransaction = (userId: string, objId: string | null, transactionId?: string) => Promise<void>;
|
|
19
|
+
export type ArchiveObjCurrentVersion = (userId: string, objId: string | null, version: number) => Promise<void>;
|
|
20
|
+
export type GetObjStatus = (userId: string, objId: string | null) => Promise<ObjStatus>;
|
|
21
21
|
export type DeleteCurrentObjVersion = (userId: string, objId: string, version?: number) => Promise<void>;
|
|
22
22
|
export type DeleteArchivedObjVersion = (userId: string, objId: string | null, version: number) => Promise<void>;
|
|
23
23
|
export type GetSpaceQuota = (userId: string) => Promise<number>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2017, 2020, 2025 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2017, 2020, 2025 - 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Response, Request } from 'express';
|
|
2
|
+
export declare function getObjIdFromParams(rootObj: boolean, req: Request): {
|
|
3
|
+
objId: string | null;
|
|
4
|
+
objIdParseErr?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function replyWithErr(status: number, msg: string, res: Response, reqToDrainBytesFrom?: Request): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2026 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.replyWithErr = exports.getObjIdFromParams = void 0;
|
|
20
|
+
const buffer_utils_1 = require("../../lib-common/buffer-utils");
|
|
21
|
+
const body_parsers_1 = require("../../lib-server/middleware/body-parsers");
|
|
22
|
+
function getObjIdFromParams(rootObj, req) {
|
|
23
|
+
if (rootObj) {
|
|
24
|
+
return { objId: null };
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const objId = req.params.objId;
|
|
28
|
+
return ((!!objId && buffer_utils_1.base64urlSafe.allCharsFromAlphabet(objId)) ?
|
|
29
|
+
{ objId } :
|
|
30
|
+
{ objId: undefined, objIdParseErr: "Bad object id" });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.getObjIdFromParams = getObjIdFromParams;
|
|
34
|
+
function replyWithErr(status, msg, res, reqToDrainBytesFrom) {
|
|
35
|
+
if (reqToDrainBytesFrom) {
|
|
36
|
+
(0, body_parsers_1.attachByteDrainToRequest)(reqToDrainBytesFrom);
|
|
37
|
+
}
|
|
38
|
+
res.status(status).json({ error: msg });
|
|
39
|
+
}
|
|
40
|
+
exports.replyWithErr = replyWithErr;
|
|
41
|
+
Object.freeze(exports);
|
|
@@ -19,18 +19,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.archiveCurrentObjVersion = void 0;
|
|
20
20
|
const users_1 = require("../../resources/users");
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
|
+
const utils_1 = require("../../resources/utils");
|
|
22
23
|
const SC = owner_1.archiveObj.SC;
|
|
23
24
|
function archiveCurrentObjVersion(root, archiveObjVerFunc) {
|
|
24
|
-
if ('function' !== typeof archiveObjVerFunc) {
|
|
25
|
-
throw new TypeError("Given argument 'archiveObjVerFunc' must be function, but is not.");
|
|
26
|
-
}
|
|
27
25
|
return async (req, res, next) => {
|
|
28
26
|
const userId = req.session.params.userId;
|
|
29
|
-
const objId = (root
|
|
27
|
+
const { objId, objIdParseErr } = (0, utils_1.getObjIdFromParams)(root, req);
|
|
28
|
+
if (objIdParseErr) {
|
|
29
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, objIdParseErr, res);
|
|
30
|
+
}
|
|
30
31
|
const version = parseInt(req.query.ver);
|
|
31
32
|
if (isNaN(version) || (version < 1)) {
|
|
32
|
-
|
|
33
|
-
return;
|
|
33
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Bad query parameters", res);
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
36
36
|
await archiveObjVerFunc(userId, objId, version);
|
|
@@ -51,12 +51,10 @@ function archiveCurrentObjVersion(root, archiveObjVerFunc) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
54
|
-
|
|
55
|
-
`Root object is not set.` :
|
|
56
|
-
`Object ${objId} is unknown.`);
|
|
54
|
+
(0, utils_1.replyWithErr)(SC.unknownObj, (root ? `Root object is not set.` : `Object ${objId} is unknown.`), res);
|
|
57
55
|
}
|
|
58
56
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
59
|
-
|
|
57
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.server, "Recipient disappeared from the system.", res);
|
|
60
58
|
req.session.close();
|
|
61
59
|
}
|
|
62
60
|
else {
|
|
@@ -19,13 +19,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.cancelTransaction = void 0;
|
|
20
20
|
const users_1 = require("../../resources/users");
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
|
+
const utils_1 = require("../../resources/utils");
|
|
22
23
|
function cancelTransaction(root, cancelTransFunc) {
|
|
23
|
-
if ('function' !== typeof cancelTransFunc) {
|
|
24
|
-
throw new TypeError("Given argument 'cancelTransFunc' must be function, but is not.");
|
|
25
|
-
}
|
|
26
24
|
return async (req, res, next) => {
|
|
27
25
|
const userId = req.session.params.userId;
|
|
28
|
-
const objId = (root
|
|
26
|
+
const { objId, objIdParseErr } = (0, utils_1.getObjIdFromParams)(root, req);
|
|
27
|
+
if (objIdParseErr) {
|
|
28
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, objIdParseErr, res);
|
|
29
|
+
}
|
|
29
30
|
const transactionId = req.params.transactionId;
|
|
30
31
|
try {
|
|
31
32
|
await cancelTransFunc(userId, objId, ((transactionId === '-') ? undefined : transactionId));
|
|
@@ -20,16 +20,17 @@ exports.deleteArchivedObjVer = exports.deleteCurrentObjVer = void 0;
|
|
|
20
20
|
const users_1 = require("../../resources/users");
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
22
|
const assert_1 = require("../../../lib-common/assert");
|
|
23
|
+
const utils_1 = require("../../resources/utils");
|
|
23
24
|
function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
24
|
-
if ('function' !== typeof deleteObjFunc) {
|
|
25
|
-
throw new TypeError("Given argument 'deleteObjFunc' must be function, but is not.");
|
|
26
|
-
}
|
|
27
25
|
if (delCurrent) {
|
|
28
26
|
(0, assert_1.assert)(!root);
|
|
29
27
|
}
|
|
30
28
|
return async (req, res, next) => {
|
|
31
29
|
const userId = req.session.params.userId;
|
|
32
|
-
const objId = (root
|
|
30
|
+
const { objId, objIdParseErr } = (0, utils_1.getObjIdFromParams)(root, req);
|
|
31
|
+
if (objIdParseErr) {
|
|
32
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, objIdParseErr, res);
|
|
33
|
+
}
|
|
33
34
|
const ver = parseInt(req.query.ver);
|
|
34
35
|
let version;
|
|
35
36
|
if (isNaN(ver)) {
|
|
@@ -37,14 +38,12 @@ function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
|
37
38
|
version = undefined;
|
|
38
39
|
}
|
|
39
40
|
else {
|
|
40
|
-
|
|
41
|
-
return;
|
|
41
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Bad query parameters", res);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
45
|
if (ver < 1) {
|
|
46
|
-
|
|
47
|
-
return;
|
|
46
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Bad query parameters", res);
|
|
48
47
|
}
|
|
49
48
|
version = ver;
|
|
50
49
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017, 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017, 2020, 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -21,6 +21,7 @@ const users_1 = require("../../resources/users");
|
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
22
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
23
23
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
24
|
+
const utils_1 = require("../../resources/utils");
|
|
24
25
|
function extractQueryOptions(req) {
|
|
25
26
|
// query fields are string or undefined, yet, type info helps the show
|
|
26
27
|
const query = req.query;
|
|
@@ -46,16 +47,15 @@ function extractQueryOptions(req) {
|
|
|
46
47
|
return { header, limit, ofs, ver };
|
|
47
48
|
}
|
|
48
49
|
function getArchivedObjVersion(root, getArchivedObjFunc) {
|
|
49
|
-
if ('function' !== typeof getArchivedObjFunc) {
|
|
50
|
-
throw new TypeError("Given argument 'getArchivedObjFunc' must be function, but is not.");
|
|
51
|
-
}
|
|
52
50
|
return async (req, res, next) => {
|
|
53
51
|
const userId = req.session.params.userId;
|
|
54
|
-
const objId = (root
|
|
52
|
+
const { objId, objIdParseErr } = (0, utils_1.getObjIdFromParams)(root, req);
|
|
53
|
+
if (objIdParseErr) {
|
|
54
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, objIdParseErr, res);
|
|
55
|
+
}
|
|
55
56
|
const opts = extractQueryOptions(req);
|
|
56
57
|
if (!opts) {
|
|
57
|
-
|
|
58
|
-
return;
|
|
58
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Bad query parameters", res);
|
|
59
59
|
}
|
|
60
60
|
try {
|
|
61
61
|
const reader = await getArchivedObjFunc(userId, objId, opts.ver, opts.header, opts.ofs, opts.limit);
|
|
@@ -86,16 +86,14 @@ function getArchivedObjVersion(root, getArchivedObjFunc) {
|
|
|
86
86
|
next(err);
|
|
87
87
|
}
|
|
88
88
|
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
89
|
-
|
|
90
|
-
`Object ${objId}is unknown.` : `Root object is not set`);
|
|
89
|
+
(0, utils_1.replyWithErr)(owner_1.archivedObjVersion.SC.unknownObj, (objId ? `Object ${objId}is unknown.` : `Root object is not set`), res);
|
|
91
90
|
}
|
|
92
91
|
else if (err === users_1.SC.OBJ_VER_UNKNOWN) {
|
|
93
|
-
|
|
94
|
-
`Object ${objId}, version ${opts.ver} is unknown.` :
|
|
95
|
-
`Root object version ${opts.ver} is not known.`);
|
|
92
|
+
(0, utils_1.replyWithErr)(owner_1.archivedObjVersion.SC.unknownObjVer, (objId ?
|
|
93
|
+
`Object ${objId}, version ${opts.ver} is unknown.` : `Root object version ${opts.ver} is not known.`), res);
|
|
96
94
|
}
|
|
97
95
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
98
|
-
|
|
96
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.server, `Recipient disappeared from the system.`, res);
|
|
99
97
|
req.session.close();
|
|
100
98
|
}
|
|
101
99
|
else {
|
|
@@ -21,6 +21,7 @@ const users_1 = require("../../resources/users");
|
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
22
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
23
23
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
24
|
+
const utils_1 = require("../../resources/utils");
|
|
24
25
|
function extractQueryOptions(req) {
|
|
25
26
|
// query fields are string or undefined, yet, type info helps the show
|
|
26
27
|
const query = req.query;
|
|
@@ -51,12 +52,12 @@ function extractQueryOptions(req) {
|
|
|
51
52
|
return { header, limit, ofs, ver };
|
|
52
53
|
}
|
|
53
54
|
function getCurrentObj(root, getCurrentObjFunc) {
|
|
54
|
-
if ('function' !== typeof getCurrentObjFunc) {
|
|
55
|
-
throw new TypeError("Given argument 'getCurrentObjFunc' must be function, but is not.");
|
|
56
|
-
}
|
|
57
55
|
return async (req, res, next) => {
|
|
58
56
|
const userId = req.session.params.userId;
|
|
59
|
-
const objId = (root
|
|
57
|
+
const { objId, objIdParseErr } = (0, utils_1.getObjIdFromParams)(root, req);
|
|
58
|
+
if (objIdParseErr) {
|
|
59
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, objIdParseErr, res);
|
|
60
|
+
}
|
|
60
61
|
const opts = extractQueryOptions(req);
|
|
61
62
|
if (!opts) {
|
|
62
63
|
res.status(owner_1.ERR_SC.malformed).send("Bad query parameters");
|
|
@@ -102,10 +103,10 @@ function getCurrentObj(root, getCurrentObjFunc) {
|
|
|
102
103
|
}
|
|
103
104
|
else if ((err === users_1.SC.OBJ_UNKNOWN)
|
|
104
105
|
|| (err === users_1.SC.OBJ_VER_UNKNOWN)) {
|
|
105
|
-
|
|
106
|
+
(0, utils_1.replyWithErr)(owner_1.currentObj.SC.unknownObj, (objId ? `Object ${objId} is unknown.` : `Root object is not set.`), res);
|
|
106
107
|
}
|
|
107
108
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
108
|
-
|
|
109
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.server, `Recipient disappeared from the system.`, res);
|
|
109
110
|
req.session.close();
|
|
110
111
|
}
|
|
111
112
|
else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2022 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2022, 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -19,13 +19,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.getObjStatus = void 0;
|
|
20
20
|
const users_1 = require("../../resources/users");
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
|
+
const utils_1 = require("../../resources/utils");
|
|
22
23
|
function getObjStatus(root, getObjStatusFunc) {
|
|
23
|
-
if ('function' !== typeof getObjStatusFunc) {
|
|
24
|
-
throw new TypeError("Given argument 'getObjStatusFunc' must be function, but is not.");
|
|
25
|
-
}
|
|
26
24
|
return async (req, res, next) => {
|
|
27
25
|
const userId = req.session.params.userId;
|
|
28
|
-
const objId = (root
|
|
26
|
+
const { objId, objIdParseErr } = (0, utils_1.getObjIdFromParams)(root, req);
|
|
27
|
+
if (objIdParseErr) {
|
|
28
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, objIdParseErr, res);
|
|
29
|
+
}
|
|
29
30
|
try {
|
|
30
31
|
const lst = await getObjStatusFunc(userId, objId);
|
|
31
32
|
res.status(owner_1.objStatus.SC.ok).json(lst);
|
|
@@ -35,11 +36,10 @@ function getObjStatus(root, getObjStatusFunc) {
|
|
|
35
36
|
next(err);
|
|
36
37
|
}
|
|
37
38
|
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
38
|
-
|
|
39
|
-
`Root object is set.` : `Object ${objId} is unknown.`);
|
|
39
|
+
(0, utils_1.replyWithErr)(owner_1.objStatus.SC.unknownObj, (root ? `Root object is set.` : `Object ${objId} is unknown.`), res);
|
|
40
40
|
}
|
|
41
41
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
42
|
-
|
|
42
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.server, "Recipient disappeared from the system.", res);
|
|
43
43
|
req.session.close();
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017, 2019 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017, 2019 - 2020, 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -20,10 +20,10 @@ exports.saveCurrentObj = void 0;
|
|
|
20
20
|
const users_1 = require("../../resources/users");
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
22
|
const conf_util_1 = require("../../../lib-server/conf-util");
|
|
23
|
-
const body_parsers_1 = require("../../../lib-server/middleware/body-parsers");
|
|
24
23
|
const common_1 = require("../../../lib-common/byte-streaming/common");
|
|
25
24
|
const processes_1 = require("../../../lib-common/processes");
|
|
26
25
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
26
|
+
const utils_1 = require("../../resources/utils");
|
|
27
27
|
function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
28
28
|
if ('function' !== typeof saveObjFunc) {
|
|
29
29
|
throw new TypeError("Given argument 'saveObjFunc' must be function, but is not.");
|
|
@@ -31,38 +31,30 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
31
31
|
const maxChunkSize = (0, conf_util_1.stringToNumOfBytes)(chunkLimit);
|
|
32
32
|
return async (req, res, next) => {
|
|
33
33
|
if (!req.is(owner_1.BIN_TYPE)) {
|
|
34
|
-
(0,
|
|
35
|
-
res.status(owner_1.ERR_SC.wrongContentType).json({
|
|
36
|
-
error: `Content-Type must be ${owner_1.BIN_TYPE} for this call.`
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
34
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.wrongContentType, `Content-Type must be ${owner_1.BIN_TYPE} for this call.`, res, req);
|
|
39
35
|
}
|
|
40
|
-
const userId = req.session.params.userId;
|
|
41
|
-
const objId = (root ? null : req.params.objId);
|
|
42
36
|
// get and check Content-Length, implicitly sending replies for bad length
|
|
43
37
|
let len = getContentLenOrSendError(req, res, maxChunkSize);
|
|
44
38
|
if (len === undefined) {
|
|
45
|
-
(0, body_parsers_1.attachByteDrainToRequest)(req);
|
|
46
39
|
return;
|
|
47
40
|
}
|
|
41
|
+
const userId = req.session.params.userId;
|
|
42
|
+
const { objId, objIdParseErr } = (0, utils_1.getObjIdFromParams)(root, req);
|
|
43
|
+
if (objIdParseErr) {
|
|
44
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, objIdParseErr, res, req);
|
|
45
|
+
}
|
|
48
46
|
// extract and check query parameters
|
|
49
47
|
const opts = extractQueryOptions(req);
|
|
50
48
|
if (!opts) {
|
|
51
|
-
return
|
|
49
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Bad query parameters", res, req);
|
|
52
50
|
}
|
|
53
51
|
const { fstReq, sndReq } = opts;
|
|
54
52
|
let diff;
|
|
55
53
|
if (fstReq) {
|
|
56
|
-
if (!root && objId) {
|
|
57
|
-
if (!buffer_utils_1.base64urlSafe.allCharsFromAlphabet(objId)) {
|
|
58
|
-
return replyToMalformed(req, "Bad object id", res);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
54
|
// cross-check given lengths
|
|
62
|
-
const diffAndHeader = fstReq.header +
|
|
63
|
-
(fstReq.diff ? fstReq.diff : 0);
|
|
55
|
+
const diffAndHeader = fstReq.header + (fstReq.diff ? fstReq.diff : 0);
|
|
64
56
|
if (diffAndHeader > len) {
|
|
65
|
-
return
|
|
57
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Bad query parameters", res, req);
|
|
66
58
|
}
|
|
67
59
|
// read diff, if it is expected
|
|
68
60
|
if (fstReq.diff) {
|
|
@@ -71,23 +63,23 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
71
63
|
len -= fstReq.diff;
|
|
72
64
|
}
|
|
73
65
|
else {
|
|
74
|
-
return
|
|
66
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Cannot read diff bytes", res, req);
|
|
75
67
|
}
|
|
76
68
|
try {
|
|
77
69
|
const diffFromReq = JSON.parse(buffer_utils_1.utf8.open(diffBytes));
|
|
78
70
|
diff = (0, owner_1.sanitizedDiff)(diffFromReq, fstReq.ver);
|
|
79
71
|
if (!diff) {
|
|
80
|
-
return
|
|
72
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Malformed diff info", res, req);
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
75
|
catch (err) {
|
|
84
|
-
return
|
|
76
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "Malformed diff info", res, req);
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
80
|
else if (sndReq) {
|
|
89
81
|
if ((len === 0) && !sndReq.last) {
|
|
90
|
-
return
|
|
82
|
+
return (0, utils_1.replyWithErr)(owner_1.ERR_SC.malformed, "No segment bytes", res, req);
|
|
91
83
|
}
|
|
92
84
|
}
|
|
93
85
|
try {
|
|
@@ -102,7 +94,7 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
102
94
|
error: "Current object version doesn't match assumed one.",
|
|
103
95
|
current_version: err.current_version
|
|
104
96
|
};
|
|
105
|
-
res.set(owner_1.HTTP_HEADER.objVersion, `${
|
|
97
|
+
res.set(owner_1.HTTP_HEADER.objVersion, `${rep.current_version}`);
|
|
106
98
|
res.status(owner_1.currentObj.SC.mismatchedObjVer).json(rep);
|
|
107
99
|
}
|
|
108
100
|
else {
|
|
@@ -111,41 +103,27 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
111
103
|
}
|
|
112
104
|
else if ((err === users_1.SC.OBJ_UNKNOWN)
|
|
113
105
|
|| (err === users_1.SC.OBJ_VER_UNKNOWN)) {
|
|
114
|
-
|
|
115
|
-
error: `Unknown object ${objId}.`
|
|
116
|
-
});
|
|
106
|
+
(0, utils_1.replyWithErr)(owner_1.currentObj.SC.unknownObj, `Unknown object ${objId}.`, res);
|
|
117
107
|
}
|
|
118
108
|
else if (err === users_1.SC.TRANSACTION_UNKNOWN) {
|
|
119
|
-
|
|
120
|
-
error: "Unknown transaction."
|
|
121
|
-
});
|
|
109
|
+
(0, utils_1.replyWithErr)(owner_1.currentObj.SC.unknownTransaction, "Unknown transaction.", res);
|
|
122
110
|
}
|
|
123
111
|
else if ((err === users_1.SC.OBJ_EXIST)
|
|
124
112
|
|| (err === users_1.SC.OBJ_VER_EXIST)) {
|
|
125
|
-
|
|
126
|
-
error: "Object already exists."
|
|
127
|
-
});
|
|
113
|
+
(0, utils_1.replyWithErr)(owner_1.currentObj.SC.objAlreadyExists, "Object already exists.", res);
|
|
128
114
|
}
|
|
129
115
|
else if (err === users_1.SC.CONCURRENT_TRANSACTION) {
|
|
130
|
-
|
|
131
|
-
error: `Object ${objId} is currently under a transaction.`
|
|
132
|
-
});
|
|
116
|
+
(0, utils_1.replyWithErr)(owner_1.currentObj.SC.concurrentTransaction, `Object ${objId} is currently under a transaction.`, res);
|
|
133
117
|
}
|
|
134
118
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
135
|
-
|
|
136
|
-
error: "Recipient disappeared from the system."
|
|
137
|
-
});
|
|
119
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.server, "Recipient disappeared from the system.", res);
|
|
138
120
|
req.session.close();
|
|
139
121
|
}
|
|
140
122
|
else if (err === users_1.SC.NOT_ENOUGH_SPACE) {
|
|
141
|
-
|
|
142
|
-
error: "Reached storage limits."
|
|
143
|
-
});
|
|
123
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.noSpace, "Reached storage limits.", res);
|
|
144
124
|
}
|
|
145
125
|
else if (err === users_1.SC.OBJ_FILE_INCOMPLETE) {
|
|
146
|
-
|
|
147
|
-
error: "Object version file is incomplete."
|
|
148
|
-
});
|
|
126
|
+
(0, utils_1.replyWithErr)(owner_1.currentObj.SC.objIncomplete, "Object version file is incomplete.", res);
|
|
149
127
|
}
|
|
150
128
|
else {
|
|
151
129
|
next(new Error(`Unhandled storage error code: ${err}`));
|
|
@@ -192,14 +170,10 @@ function extractQueryOptions(req) {
|
|
|
192
170
|
function getContentLenOrSendError(req, res, maxChunkSize) {
|
|
193
171
|
const contentLength = parseInt(req.get(owner_1.HTTP_HEADER.contentLength));
|
|
194
172
|
if (isNaN(contentLength)) {
|
|
195
|
-
|
|
196
|
-
error: "Content-Length header is required with proper number."
|
|
197
|
-
});
|
|
173
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.contentLenMissing, "Content-Length header is required with proper number.", res, req);
|
|
198
174
|
}
|
|
199
175
|
else if (contentLength > maxChunkSize) {
|
|
200
|
-
|
|
201
|
-
error: "Request body is too long."
|
|
202
|
-
});
|
|
176
|
+
(0, utils_1.replyWithErr)(owner_1.ERR_SC.contentTooLong, "Request body is too long.", res, req);
|
|
203
177
|
}
|
|
204
178
|
else {
|
|
205
179
|
return contentLength;
|
|
@@ -269,9 +243,5 @@ function readChunkFrom(stream, bytesToRead) {
|
|
|
269
243
|
stream.on('end', onEnd);
|
|
270
244
|
return deferred.promise;
|
|
271
245
|
}
|
|
272
|
-
function replyToMalformed(req, msg, res) {
|
|
273
|
-
(0, body_parsers_1.attachByteDrainToRequest)(req);
|
|
274
|
-
res.status(owner_1.ERR_SC.malformed).json({ error: msg });
|
|
275
|
-
}
|
|
276
246
|
function noop() { }
|
|
277
247
|
Object.freeze(exports);
|
|
@@ -23,6 +23,8 @@ const conf_util_1 = require("../../../lib-server/conf-util");
|
|
|
23
23
|
function sessionParams(maxChunk) {
|
|
24
24
|
const maxChunkSize = (0, conf_util_1.stringToNumOfBytes)(maxChunk);
|
|
25
25
|
return async (req, res, next) => {
|
|
26
|
+
// XXX currently session params are same for all, hence, userId is unused, but, this whole
|
|
27
|
+
// thing must be within a session
|
|
26
28
|
const userId = req.session.params.userId;
|
|
27
29
|
try {
|
|
28
30
|
const reply = { maxChunkSize };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Response, Request } from 'express';
|
|
2
|
+
export declare function getObjIdFromParams(req: Request): {
|
|
3
|
+
objId: string;
|
|
4
|
+
objIdParseErr?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function replyWithErr(status: number, msg: string, res: Response, reqToDrainBytesFrom?: Request): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2026 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.replyWithErr = exports.getObjIdFromParams = void 0;
|
|
20
|
+
const buffer_utils_1 = require("../../lib-common/buffer-utils");
|
|
21
|
+
const body_parsers_1 = require("../../lib-server/middleware/body-parsers");
|
|
22
|
+
function getObjIdFromParams(req) {
|
|
23
|
+
const objId = req.params.objId;
|
|
24
|
+
return ((!!objId && buffer_utils_1.base64urlSafe.allCharsFromAlphabet(objId)) ?
|
|
25
|
+
{ objId } :
|
|
26
|
+
{ objId: undefined, objIdParseErr: "Bad object id" });
|
|
27
|
+
}
|
|
28
|
+
exports.getObjIdFromParams = getObjIdFromParams;
|
|
29
|
+
function replyWithErr(status, msg, res, reqToDrainBytesFrom) {
|
|
30
|
+
if (reqToDrainBytesFrom) {
|
|
31
|
+
(0, body_parsers_1.attachByteDrainToRequest)(reqToDrainBytesFrom);
|
|
32
|
+
}
|
|
33
|
+
res.status(status).json({ error: msg });
|
|
34
|
+
}
|
|
35
|
+
exports.replyWithErr = replyWithErr;
|
|
36
|
+
Object.freeze(exports);
|
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.finalizeDelivery = void 0;
|
|
20
20
|
const recipients_1 = require("../../resources/recipients");
|
|
21
21
|
const delivery_1 = require("../../../lib-common/service-api/asmail/delivery");
|
|
22
|
+
const utils_1 = require("../../resources/utils");
|
|
22
23
|
function finalizeDelivery(finDelivFunc) {
|
|
23
24
|
return async (req, res, next) => {
|
|
24
25
|
const session = req.session;
|
|
@@ -35,11 +36,11 @@ function finalizeDelivery(finDelivFunc) {
|
|
|
35
36
|
}
|
|
36
37
|
else if (err === recipients_1.SC.USER_UNKNOWN) {
|
|
37
38
|
session.close();
|
|
38
|
-
|
|
39
|
+
(0, utils_1.replyWithErr)(delivery_1.ERR_SC.server, "Recipient disappeared from the system.", res);
|
|
39
40
|
}
|
|
40
41
|
else if (err === recipients_1.SC.MSG_UNKNOWN) {
|
|
41
42
|
session.close();
|
|
42
|
-
|
|
43
|
+
(0, utils_1.replyWithErr)(delivery_1.ERR_SC.server, "Message disappeared from the system.", res);
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
46
|
next(new Error("Unhandled storage error code: " + err));
|