@casual-simulation/aux-records 3.4.6-alpha.14601027727 → 3.5.0-alpha.15117651144
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/AIController.js +835 -890
- package/AIController.js.map +1 -1
- package/AIHumeInterface.js +43 -54
- package/AIHumeInterface.js.map +1 -1
- package/AIOpenAIRealtimeInterface.js +60 -71
- package/AIOpenAIRealtimeInterface.js.map +1 -1
- package/AnthropicAIChatInterface.js +96 -142
- package/AnthropicAIChatInterface.js.map +1 -1
- package/AuthController.d.ts +3 -2
- package/AuthController.js +1907 -1933
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +1 -10
- package/BlockadeLabsGenerateSkyboxInterface.js +57 -72
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
- package/CachingConfigStore.js +30 -45
- package/CachingConfigStore.js.map +1 -1
- package/CachingPolicyStore.d.ts +8 -2
- package/CachingPolicyStore.js +108 -135
- package/CachingPolicyStore.js.map +1 -1
- package/ComIdConfig.d.ts +18 -18
- package/ComIdConfig.js.map +1 -1
- package/ConsoleAuthMessenger.js +7 -20
- package/ConsoleAuthMessenger.js.map +1 -1
- package/DataRecordsController.d.ts +2 -2
- package/DataRecordsController.js +369 -377
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +1 -1
- package/DataRecordsStore.js +1 -1
- package/DataRecordsStore.js.map +1 -1
- package/EventRecordsController.js +226 -240
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.d.ts +13 -2
- package/FileRecordsController.js +458 -450
- package/FileRecordsController.js.map +1 -1
- package/GoogleAIChatInterface.js +133 -179
- package/GoogleAIChatInterface.js.map +1 -1
- package/LivekitController.js +43 -54
- package/LivekitController.js.map +1 -1
- package/LoomController.js +64 -75
- package/LoomController.js.map +1 -1
- package/MemoryAuthMessenger.js +10 -23
- package/MemoryAuthMessenger.js.map +1 -1
- package/MemoryCache.js +18 -35
- package/MemoryCache.js.map +1 -1
- package/MemoryFileRecordsLookup.js +105 -125
- package/MemoryFileRecordsLookup.js.map +1 -1
- package/MemoryModerationJobProvider.js +17 -30
- package/MemoryModerationJobProvider.js.map +1 -1
- package/MemoryRateLimiter.js +12 -27
- package/MemoryRateLimiter.js.map +1 -1
- package/MemoryStore.d.ts +18 -6
- package/MemoryStore.js +1879 -1997
- package/MemoryStore.js.map +1 -1
- package/MetricsStore.d.ts +2 -2
- package/ModerationController.js +186 -200
- package/ModerationController.js.map +1 -1
- package/OpenAIChatInterface.js +105 -135
- package/OpenAIChatInterface.js.map +1 -1
- package/OpenAIImageInterface.js +57 -51
- package/OpenAIImageInterface.js.map +1 -1
- package/PolicyController.d.ts +150 -10
- package/PolicyController.js +1546 -1299
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +110 -2
- package/PolicyStore.js +36 -1
- package/PolicyStore.js.map +1 -1
- package/PrivoClient.js +398 -435
- package/PrivoClient.js.map +1 -1
- package/RateLimitController.js +25 -36
- package/RateLimitController.js.map +1 -1
- package/RecordsClient.js +51 -74
- package/RecordsClient.js.map +1 -1
- package/RecordsController.d.ts +2 -42
- package/RecordsController.js +1026 -1182
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +196 -27
- package/RecordsServer.js +1701 -1343
- package/RecordsServer.js.map +1 -1
- package/RecordsStore.d.ts +1 -10
- package/RecordsStore.js.map +1 -1
- package/ServerConfig.d.ts +339 -195
- package/ServerConfig.js +13 -0
- package/ServerConfig.js.map +1 -1
- package/SloydInterface.js +62 -75
- package/SloydInterface.js.map +1 -1
- package/StabilityAIImageInterface.js +150 -167
- package/StabilityAIImageInterface.js.map +1 -1
- package/SubscriptionConfigBuilder.d.ts +6 -1
- package/SubscriptionConfigBuilder.js +22 -0
- package/SubscriptionConfigBuilder.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +266 -169
- package/SubscriptionConfiguration.js +101 -79
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +2 -1
- package/SubscriptionController.js +643 -650
- package/SubscriptionController.js.map +1 -1
- package/SystemNotificationMessenger.d.ts +21 -4
- package/SystemNotificationMessenger.js +36 -30
- package/SystemNotificationMessenger.js.map +1 -1
- package/TestUtils.d.ts +9 -1
- package/TestUtils.js +105 -129
- package/TestUtils.js.map +1 -1
- package/Utils.d.ts +2 -16
- package/Utils.js +21 -22
- package/Utils.js.map +1 -1
- package/crud/CrudHelpers.js +17 -26
- package/crud/CrudHelpers.js.map +1 -1
- package/crud/CrudRecordsController.d.ts +1 -1
- package/crud/CrudRecordsController.js +259 -267
- package/crud/CrudRecordsController.js.map +1 -1
- package/crud/CrudRecordsControllerTests.js +174 -185
- package/crud/CrudRecordsControllerTests.js.map +1 -1
- package/crud/CrudRecordsStore.d.ts +7 -3
- package/crud/MemoryCrudRecordsStore.d.ts +4 -4
- package/crud/MemoryCrudRecordsStore.js +98 -118
- package/crud/MemoryCrudRecordsStore.js.map +1 -1
- package/crud/sub/MemorySubCrudRecordsStore.d.ts +24 -0
- package/crud/sub/MemorySubCrudRecordsStore.js +146 -0
- package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -0
- package/crud/sub/SubCrudRecordsController.d.ts +182 -0
- package/crud/sub/SubCrudRecordsController.js +360 -0
- package/crud/sub/SubCrudRecordsController.js.map +1 -0
- package/crud/sub/SubCrudRecordsControllerTests.d.ts +39 -0
- package/crud/sub/SubCrudRecordsControllerTests.js +821 -0
- package/crud/sub/SubCrudRecordsControllerTests.js.map +1 -0
- package/crud/sub/SubCrudRecordsStore.d.ts +95 -0
- package/{forms/index.js → crud/sub/SubCrudRecordsStore.js} +2 -2
- package/crud/sub/SubCrudRecordsStore.js.map +1 -0
- package/crud/sub/index.d.ts +3 -0
- package/crud/sub/index.js +20 -0
- package/{forms → crud/sub}/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/notifications/MemoryNotificationRecordsStore.js +189 -198
- package/notifications/MemoryNotificationRecordsStore.js.map +1 -1
- package/notifications/NotificationRecordsController.js +438 -460
- package/notifications/NotificationRecordsController.js.map +1 -1
- package/notifications/NotificationRecordsStore.d.ts +2 -1
- package/notifications/WebPushInterface.d.ts +0 -1
- package/notifications/WebPushInterface.js +0 -1
- package/notifications/WebPushInterface.js.map +1 -1
- package/package.json +6 -6
- package/packages/MemoryPackageRecordsStore.d.ts +10 -0
- package/packages/MemoryPackageRecordsStore.js +38 -0
- package/packages/MemoryPackageRecordsStore.js.map +1 -0
- package/packages/PackageRecordsController.d.ts +26 -0
- package/packages/PackageRecordsController.js +49 -0
- package/packages/PackageRecordsController.js.map +1 -0
- package/packages/PackageRecordsStore.d.ts +32 -0
- package/packages/PackageRecordsStore.js +19 -0
- package/packages/PackageRecordsStore.js.map +1 -0
- package/packages/index.d.ts +4 -0
- package/packages/index.js +21 -0
- package/packages/index.js.map +1 -0
- package/packages/version/MemoryPackageVersionRecordsStore.d.ts +21 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js +177 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -0
- package/packages/version/PackageVersionRecordsController.d.ts +144 -0
- package/packages/version/PackageVersionRecordsController.js +656 -0
- package/packages/version/PackageVersionRecordsController.js.map +1 -0
- package/packages/version/PackageVersionRecordsStore.d.ts +342 -0
- package/packages/version/PackageVersionRecordsStore.js +126 -0
- package/packages/version/PackageVersionRecordsStore.js.map +1 -0
- package/packages/version/index.d.ts +4 -0
- package/packages/version/index.js +21 -0
- package/packages/version/index.js.map +1 -0
- package/tracing/TracingDecorators.js +31 -40
- package/tracing/TracingDecorators.js.map +1 -1
- package/webhooks/MemoryWebhookRecordsStore.js +56 -72
- package/webhooks/MemoryWebhookRecordsStore.js.map +1 -1
- package/webhooks/WebhookEnvironment.d.ts +3 -3
- package/webhooks/WebhookRecordsController.d.ts +2 -1
- package/webhooks/WebhookRecordsController.js +389 -382
- package/webhooks/WebhookRecordsController.js.map +1 -1
- package/webhooks/WebhookRecordsStore.d.ts +2 -1
- package/websockets/InstRecordsStore.d.ts +50 -0
- package/websockets/InstRecordsStore.js +17 -0
- package/websockets/InstRecordsStore.js.map +1 -1
- package/websockets/MemoryTempInstRecordsStore.d.ts +5 -0
- package/websockets/MemoryTempInstRecordsStore.js +168 -179
- package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
- package/websockets/MemoryWebsocketConnectionStore.js +98 -135
- package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
- package/websockets/MemoryWebsocketMessenger.js +29 -48
- package/websockets/MemoryWebsocketMessenger.js.map +1 -1
- package/websockets/SplitInstRecordsStore.d.ts +4 -1
- package/websockets/SplitInstRecordsStore.js +167 -185
- package/websockets/SplitInstRecordsStore.js.map +1 -1
- package/websockets/TemporaryInstRecordsStore.d.ts +19 -1
- package/websockets/TemporaryInstRecordsStore.js +17 -0
- package/websockets/TemporaryInstRecordsStore.js.map +1 -1
- package/websockets/WebsocketController.d.ts +147 -3
- package/websockets/WebsocketController.js +1735 -1391
- package/websockets/WebsocketController.js.map +1 -1
- package/websockets/index.d.ts +0 -1
- package/websockets/index.js +0 -1
- package/websockets/index.js.map +1 -1
- package/AAGUID.d.ts +0 -11
- package/AAGUID.js +0 -116
- package/AAGUID.js.map +0 -1
- package/AuthUtils.d.ts +0 -162
- package/AuthUtils.js +0 -327
- package/AuthUtils.js.map +0 -1
- package/forms/FormError.d.ts +0 -43
- package/forms/FormError.js +0 -56
- package/forms/FormError.js.map +0 -1
- package/forms/index.d.ts +0 -2
- package/websockets/Utils.d.ts +0 -33
- package/websockets/Utils.js +0 -82
- package/websockets/Utils.js.map +0 -1
package/FileRecordsController.js
CHANGED
|
@@ -4,18 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
7
|
import { getExtension } from 'mime';
|
|
17
8
|
import { getMarkerResourcesForCreation, getMarkerResourcesForUpdate, } from './PolicyController';
|
|
18
|
-
import { ACCOUNT_MARKER
|
|
9
|
+
import { ACCOUNT_MARKER } from '@casual-simulation/aux-common';
|
|
19
10
|
import { getMarkersOrDefault, getRootMarkersOrDefault } from './Utils';
|
|
20
11
|
import { getSubscriptionFeatures } from './SubscriptionConfiguration';
|
|
21
12
|
import { traced } from './tracing/TracingDecorators';
|
|
@@ -36,196 +27,221 @@ export class FileRecordsController {
|
|
|
36
27
|
* @param recordNameOrKey The name of the record or the record key of the record.
|
|
37
28
|
* @param userId The ID of the user that is logged in. Should be null if the user is not logged in.
|
|
38
29
|
* @param request The request.
|
|
30
|
+
* @param userRole the role of the user that is requesting the file.
|
|
39
31
|
* @returns
|
|
40
32
|
*/
|
|
41
|
-
recordFile(recordKeyOrRecordName, userId, request) {
|
|
33
|
+
async recordFile(recordKeyOrRecordName, userId, request) {
|
|
42
34
|
var _a, _b;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
35
|
+
try {
|
|
36
|
+
let markers = getMarkersOrDefault(request.markers);
|
|
37
|
+
let rootMarkers = getRootMarkersOrDefault(markers);
|
|
38
|
+
const contextResult = await this._policies.constructAuthorizationContext({
|
|
39
|
+
recordKeyOrRecordName,
|
|
40
|
+
userId,
|
|
41
|
+
userRole: request.userRole,
|
|
42
|
+
});
|
|
43
|
+
if (contextResult.success === false) {
|
|
44
|
+
return contextResult;
|
|
45
|
+
}
|
|
46
|
+
const extension = getExtension(request.fileMimeType);
|
|
47
|
+
const fileName = extension
|
|
48
|
+
? `${request.fileSha256Hex}.${extension}`
|
|
49
|
+
: request.fileSha256Hex;
|
|
50
|
+
const authorization = await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
|
|
51
|
+
userId,
|
|
52
|
+
instances: request.instances,
|
|
53
|
+
resources: [
|
|
54
|
+
{
|
|
55
|
+
resourceKind: 'file',
|
|
56
|
+
resourceId: fileName,
|
|
57
|
+
action: 'create',
|
|
58
|
+
markers: rootMarkers,
|
|
59
|
+
},
|
|
60
|
+
...getMarkerResourcesForCreation(rootMarkers),
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
// const result = await this._policies.authorizeRequest({
|
|
64
|
+
// action: 'file.create',
|
|
65
|
+
// recordKeyOrRecordName: recordKeyOrRecordName,
|
|
66
|
+
// userId,
|
|
67
|
+
// resourceMarkers: markers,
|
|
68
|
+
// fileSizeInBytes: request.fileByteLength,
|
|
69
|
+
// fileMimeType: request.fileMimeType,
|
|
70
|
+
// instances: request.instances,
|
|
71
|
+
// });
|
|
72
|
+
if (authorization.success === false) {
|
|
73
|
+
return authorization;
|
|
74
|
+
}
|
|
75
|
+
const createAuthorization = authorization.results[0];
|
|
76
|
+
for (let result of createAuthorization.results) {
|
|
77
|
+
const options = result.permission.options;
|
|
78
|
+
if ('maxFileSizeInBytes' in options &&
|
|
79
|
+
options.maxFileSizeInBytes > 0) {
|
|
80
|
+
if (request.fileByteLength > options.maxFileSizeInBytes) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
errorCode: 'unacceptable_request',
|
|
84
|
+
errorMessage: 'The file is too large.',
|
|
85
|
+
};
|
|
95
86
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
87
|
+
}
|
|
88
|
+
else if ('allowedMimeTypes' in options &&
|
|
89
|
+
Array.isArray(options.allowedMimeTypes)) {
|
|
90
|
+
if (!options.allowedMimeTypes.includes(request.fileMimeType)) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
errorCode: 'unacceptable_request',
|
|
94
|
+
errorMessage: 'The file type is not allowed.',
|
|
95
|
+
};
|
|
105
96
|
}
|
|
106
97
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
}
|
|
99
|
+
const policy = contextResult.context.subjectPolicy;
|
|
100
|
+
userId = contextResult.context.userId;
|
|
101
|
+
const userRole = contextResult.context.userRole;
|
|
102
|
+
if (!userId && userRole === 'none' && policy !== 'subjectless') {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
errorCode: 'not_logged_in',
|
|
106
|
+
errorMessage: 'The user must be logged in in order to record files.',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (policy === 'subjectless') {
|
|
110
|
+
userId = null;
|
|
111
|
+
}
|
|
112
|
+
const publisherId = (_b = (_a = contextResult.context.recordKeyCreatorId) !== null && _a !== void 0 ? _a : userId) !== null && _b !== void 0 ? _b : contextResult.context.recordOwnerId;
|
|
113
|
+
const recordName = authorization.recordName;
|
|
114
|
+
const subjectId = userId;
|
|
115
|
+
const metricsResult = await this._metrics.getSubscriptionFileMetricsByRecordName(recordName);
|
|
116
|
+
const config = await this._config.getSubscriptionConfiguration();
|
|
117
|
+
const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
|
|
118
|
+
if (!features.files.allowed) {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
errorCode: 'not_authorized',
|
|
122
|
+
errorMessage: 'The subscription does not permit the recording of files.',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (features.files.maxBytesPerFile > 0) {
|
|
126
|
+
if (request.fileByteLength > features.files.maxBytesPerFile) {
|
|
110
127
|
return {
|
|
111
128
|
success: false,
|
|
112
|
-
errorCode: '
|
|
113
|
-
errorMessage: 'The
|
|
129
|
+
errorCode: 'unacceptable_request',
|
|
130
|
+
errorMessage: 'The file is too large.',
|
|
114
131
|
};
|
|
115
132
|
}
|
|
116
|
-
|
|
117
|
-
|
|
133
|
+
}
|
|
134
|
+
if (features.files.maxBytesTotal > 0) {
|
|
135
|
+
const newSize = metricsResult.totalFileBytesReserved +
|
|
136
|
+
request.fileByteLength;
|
|
137
|
+
if (newSize > features.files.maxBytesTotal) {
|
|
138
|
+
return {
|
|
139
|
+
success: false,
|
|
140
|
+
errorCode: 'subscription_limit_reached',
|
|
141
|
+
errorMessage: 'The file storage limit has been reached for the subscription.',
|
|
142
|
+
};
|
|
118
143
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
const config = yield this._config.getSubscriptionConfiguration();
|
|
124
|
-
const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
|
|
125
|
-
if (!features.files.allowed) {
|
|
144
|
+
}
|
|
145
|
+
if (features.files.maxFiles > 0) {
|
|
146
|
+
const newCount = metricsResult.totalFiles + 1;
|
|
147
|
+
if (newCount > features.files.maxFiles) {
|
|
126
148
|
return {
|
|
127
149
|
success: false,
|
|
128
|
-
errorCode: '
|
|
129
|
-
errorMessage: 'The
|
|
150
|
+
errorCode: 'subscription_limit_reached',
|
|
151
|
+
errorMessage: 'The file count limit has been reached for the subscription.',
|
|
130
152
|
};
|
|
131
153
|
}
|
|
132
|
-
|
|
133
|
-
|
|
154
|
+
}
|
|
155
|
+
const addFileResult = await this._store.addFileRecord(recordName, fileName, publisherId, subjectId, request.fileByteLength, request.fileDescription, markers);
|
|
156
|
+
if (addFileResult.success === false) {
|
|
157
|
+
if (addFileResult.errorCode === 'file_already_exists') {
|
|
158
|
+
const fileResult = await this._store.getFileRecord(recordName, fileName);
|
|
159
|
+
if (fileResult.success === false) {
|
|
160
|
+
console.error('[FileRecordsController] Error getting file record even though it should exist:', fileResult);
|
|
134
161
|
return {
|
|
135
162
|
success: false,
|
|
136
|
-
errorCode: '
|
|
137
|
-
errorMessage:
|
|
163
|
+
errorCode: 'server_error',
|
|
164
|
+
errorMessage: fileResult.errorMessage,
|
|
138
165
|
};
|
|
139
166
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
167
|
+
if (!fileResult.uploaded) {
|
|
168
|
+
if (!fileResult.markers.some((m) => markers.includes(m))) {
|
|
169
|
+
// re-check permissions because none of the markers match up
|
|
170
|
+
// with the markers that the file actually has
|
|
171
|
+
markers = fileResult.markers;
|
|
172
|
+
rootMarkers = getRootMarkersOrDefault(markers);
|
|
173
|
+
const authorization = await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
|
|
174
|
+
userId: subjectId,
|
|
175
|
+
instances: request.instances,
|
|
176
|
+
resources: [
|
|
177
|
+
{
|
|
178
|
+
resourceKind: 'file',
|
|
179
|
+
resourceId: fileName,
|
|
180
|
+
action: 'create',
|
|
181
|
+
markers: markers,
|
|
182
|
+
},
|
|
183
|
+
...getMarkerResourcesForCreation(markers),
|
|
184
|
+
],
|
|
185
|
+
});
|
|
186
|
+
if (authorization.success === false) {
|
|
187
|
+
return authorization;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// allow the request to be successful
|
|
192
|
+
// because at least one of the markers is the same
|
|
193
|
+
// we just need to grab the real markers from the file
|
|
194
|
+
markers = fileResult.markers;
|
|
195
|
+
rootMarkers = getRootMarkersOrDefault(markers);
|
|
196
|
+
}
|
|
150
197
|
}
|
|
151
|
-
|
|
152
|
-
if (features.files.maxFiles > 0) {
|
|
153
|
-
const newCount = metricsResult.totalFiles + 1;
|
|
154
|
-
if (newCount > features.files.maxFiles) {
|
|
198
|
+
else {
|
|
155
199
|
return {
|
|
156
200
|
success: false,
|
|
157
|
-
errorCode: '
|
|
158
|
-
errorMessage: 'The file
|
|
201
|
+
errorCode: 'file_already_exists',
|
|
202
|
+
errorMessage: 'The file has already been uploaded to ' +
|
|
203
|
+
fileResult.url,
|
|
204
|
+
existingFileUrl: fileResult.url,
|
|
205
|
+
existingFileName: fileResult.fileName,
|
|
159
206
|
};
|
|
160
207
|
}
|
|
161
208
|
}
|
|
162
|
-
|
|
163
|
-
recordName,
|
|
164
|
-
fileName: fileName,
|
|
165
|
-
fileSha256Hex: request.fileSha256Hex,
|
|
166
|
-
fileMimeType: request.fileMimeType,
|
|
167
|
-
fileByteLength: request.fileByteLength,
|
|
168
|
-
markers: rootMarkers,
|
|
169
|
-
headers: request.headers,
|
|
170
|
-
});
|
|
171
|
-
if (presignResult.success === false) {
|
|
172
|
-
return presignResult;
|
|
173
|
-
}
|
|
174
|
-
const addFileResult = yield this._store.addFileRecord(recordName, fileName, publisherId, subjectId, request.fileByteLength, request.fileDescription, markers);
|
|
175
|
-
if (addFileResult.success === false) {
|
|
176
|
-
if (addFileResult.errorCode === 'file_already_exists') {
|
|
177
|
-
const fileResult = yield this._store.getFileRecord(recordName, fileName);
|
|
178
|
-
if (fileResult.success === false) {
|
|
179
|
-
console.error('[FileRecordsController] Error getting file record even though it should exist:', fileResult);
|
|
180
|
-
return {
|
|
181
|
-
success: false,
|
|
182
|
-
errorCode: 'server_error',
|
|
183
|
-
errorMessage: fileResult.errorMessage,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
if (!fileResult.uploaded) {
|
|
187
|
-
return {
|
|
188
|
-
success: true,
|
|
189
|
-
fileName,
|
|
190
|
-
uploadUrl: presignResult.uploadUrl,
|
|
191
|
-
uploadHeaders: presignResult.uploadHeaders,
|
|
192
|
-
uploadMethod: presignResult.uploadMethod,
|
|
193
|
-
markers,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
return {
|
|
198
|
-
success: false,
|
|
199
|
-
errorCode: 'file_already_exists',
|
|
200
|
-
errorMessage: 'The file has already been uploaded to ' +
|
|
201
|
-
fileResult.url,
|
|
202
|
-
existingFileUrl: fileResult.url,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
209
|
+
else {
|
|
206
210
|
return addFileResult;
|
|
207
211
|
}
|
|
208
|
-
return {
|
|
209
|
-
success: true,
|
|
210
|
-
fileName,
|
|
211
|
-
uploadUrl: presignResult.uploadUrl,
|
|
212
|
-
uploadHeaders: presignResult.uploadHeaders,
|
|
213
|
-
uploadMethod: presignResult.uploadMethod,
|
|
214
|
-
markers,
|
|
215
|
-
};
|
|
216
212
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
213
|
+
const presignResult = await this._store.presignFileUpload({
|
|
214
|
+
recordName,
|
|
215
|
+
fileName: fileName,
|
|
216
|
+
fileSha256Hex: request.fileSha256Hex,
|
|
217
|
+
fileMimeType: request.fileMimeType,
|
|
218
|
+
fileByteLength: request.fileByteLength,
|
|
219
|
+
markers: rootMarkers,
|
|
220
|
+
headers: request.headers,
|
|
221
|
+
});
|
|
222
|
+
if (presignResult.success === false) {
|
|
223
|
+
return presignResult;
|
|
227
224
|
}
|
|
228
|
-
|
|
225
|
+
return {
|
|
226
|
+
success: true,
|
|
227
|
+
fileName,
|
|
228
|
+
uploadUrl: presignResult.uploadUrl,
|
|
229
|
+
uploadHeaders: presignResult.uploadHeaders,
|
|
230
|
+
uploadMethod: presignResult.uploadMethod,
|
|
231
|
+
markers,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
const span = trace.getActiveSpan();
|
|
236
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
237
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
238
|
+
console.error('[FileRecordsController] An error occurred while recording a file:', err);
|
|
239
|
+
return {
|
|
240
|
+
success: false,
|
|
241
|
+
errorCode: 'server_error',
|
|
242
|
+
errorMessage: 'A server error occurred.',
|
|
243
|
+
};
|
|
244
|
+
}
|
|
229
245
|
}
|
|
230
246
|
/**
|
|
231
247
|
* Attempts to erase the given file using the given record key and subject.
|
|
@@ -234,80 +250,78 @@ export class FileRecordsController {
|
|
|
234
250
|
* @param subjectId The ID of the user that is making this request. Null if the user is not logged in.
|
|
235
251
|
* @param instances The instances that are loaded.
|
|
236
252
|
*/
|
|
237
|
-
eraseFile(recordKeyOrRecordName, fileName, subjectId, instances) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (!subjectId && policy !== 'subjectless') {
|
|
278
|
-
return {
|
|
279
|
-
success: false,
|
|
280
|
-
errorCode: 'not_logged_in',
|
|
281
|
-
errorMessage: 'The user must be logged in in order to erase files.',
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
const recordName = authorization.recordName;
|
|
285
|
-
const eraseResult = yield this._store.eraseFileRecord(recordName, fileName);
|
|
286
|
-
if (eraseResult.success === false) {
|
|
287
|
-
return {
|
|
288
|
-
success: false,
|
|
289
|
-
errorCode: eraseResult.errorCode,
|
|
290
|
-
errorMessage: eraseResult.errorMessage,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
253
|
+
async eraseFile(recordKeyOrRecordName, fileName, subjectId, instances) {
|
|
254
|
+
try {
|
|
255
|
+
const baseRequest = {
|
|
256
|
+
recordKeyOrRecordName,
|
|
257
|
+
userId: subjectId,
|
|
258
|
+
instances,
|
|
259
|
+
};
|
|
260
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
261
|
+
if (context.success === false) {
|
|
262
|
+
return context;
|
|
263
|
+
}
|
|
264
|
+
const fileResult = await this._store.getFileRecord(context.context.recordName, fileName);
|
|
265
|
+
if (fileResult.success === false) {
|
|
266
|
+
return fileResult;
|
|
267
|
+
}
|
|
268
|
+
const markers = getRootMarkersOrDefault(fileResult.markers);
|
|
269
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
270
|
+
userId: subjectId,
|
|
271
|
+
instances: instances,
|
|
272
|
+
resourceKind: 'file',
|
|
273
|
+
resourceId: fileName,
|
|
274
|
+
action: 'delete',
|
|
275
|
+
markers: markers,
|
|
276
|
+
});
|
|
277
|
+
// const result = await this._policies.authorizeRequestUsingContext(
|
|
278
|
+
// context.context,
|
|
279
|
+
// {
|
|
280
|
+
// action: 'file.delete',
|
|
281
|
+
// ...baseRequest,
|
|
282
|
+
// fileSizeInBytes: fileResult.sizeInBytes,
|
|
283
|
+
// fileMimeType: getType(fileResult.fileName),
|
|
284
|
+
// resourceMarkers: markers,
|
|
285
|
+
// }
|
|
286
|
+
// );
|
|
287
|
+
if (authorization.success === false) {
|
|
288
|
+
return authorization;
|
|
289
|
+
}
|
|
290
|
+
const policy = context.context.subjectPolicy;
|
|
291
|
+
subjectId = authorization.user.subjectId;
|
|
292
|
+
if (!subjectId && policy !== 'subjectless') {
|
|
293
293
|
return {
|
|
294
|
-
success:
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
success: false,
|
|
295
|
+
errorCode: 'not_logged_in',
|
|
296
|
+
errorMessage: 'The user must be logged in in order to erase files.',
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
303
|
-
console.error('[FileRecordsController] An error occurred while erasing a file:', err);
|
|
299
|
+
const recordName = authorization.recordName;
|
|
300
|
+
const eraseResult = await this._store.eraseFileRecord(recordName, fileName);
|
|
301
|
+
if (eraseResult.success === false) {
|
|
304
302
|
return {
|
|
305
303
|
success: false,
|
|
306
|
-
errorCode:
|
|
307
|
-
errorMessage:
|
|
304
|
+
errorCode: eraseResult.errorCode,
|
|
305
|
+
errorMessage: eraseResult.errorMessage,
|
|
308
306
|
};
|
|
309
307
|
}
|
|
310
|
-
|
|
308
|
+
return {
|
|
309
|
+
success: true,
|
|
310
|
+
recordName,
|
|
311
|
+
fileName,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
const span = trace.getActiveSpan();
|
|
316
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
317
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
318
|
+
console.error('[FileRecordsController] An error occurred while erasing a file:', err);
|
|
319
|
+
return {
|
|
320
|
+
success: false,
|
|
321
|
+
errorCode: 'server_error',
|
|
322
|
+
errorMessage: 'A server error occurred.',
|
|
323
|
+
};
|
|
324
|
+
}
|
|
311
325
|
}
|
|
312
326
|
/**
|
|
313
327
|
* Attempts to retrieve a URL that allows the client to read the given file.
|
|
@@ -315,86 +329,88 @@ export class FileRecordsController {
|
|
|
315
329
|
* @param fileName The name of the file.
|
|
316
330
|
* @param subjectId The ID of the user that is making this request. Null if the user is not logged in.
|
|
317
331
|
* @param instances The instances that are loaded.
|
|
332
|
+
* @param userRole The role of the user that is making the request.
|
|
318
333
|
*/
|
|
319
|
-
readFile(recordKeyOrRecordName, fileName, subjectId, instances) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
errorCode: 'not_logged_in',
|
|
363
|
-
errorMessage: 'The user must be logged in in order to read files.',
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
const recordName = result.recordName;
|
|
367
|
-
const readResult = yield this._store.presignFileRead({
|
|
368
|
-
recordName,
|
|
369
|
-
fileName,
|
|
370
|
-
headers: {},
|
|
371
|
-
});
|
|
372
|
-
if (readResult.success === false) {
|
|
373
|
-
return {
|
|
374
|
-
success: false,
|
|
375
|
-
errorCode: readResult.errorCode,
|
|
376
|
-
errorMessage: readResult.errorMessage,
|
|
377
|
-
};
|
|
378
|
-
}
|
|
334
|
+
async readFile(recordKeyOrRecordName, fileName, subjectId, instances, userRole) {
|
|
335
|
+
try {
|
|
336
|
+
const baseRequest = {
|
|
337
|
+
recordKeyOrRecordName,
|
|
338
|
+
userId: subjectId,
|
|
339
|
+
instances,
|
|
340
|
+
userRole,
|
|
341
|
+
};
|
|
342
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
343
|
+
if (context.success === false) {
|
|
344
|
+
return context;
|
|
345
|
+
}
|
|
346
|
+
const fileResult = await this._store.getFileRecord(context.context.recordName, fileName);
|
|
347
|
+
if (fileResult.success === false) {
|
|
348
|
+
return fileResult;
|
|
349
|
+
}
|
|
350
|
+
const markers = getRootMarkersOrDefault(fileResult.markers);
|
|
351
|
+
const result = await this._policies.authorizeUserAndInstances(context.context, {
|
|
352
|
+
userId: subjectId,
|
|
353
|
+
instances: instances,
|
|
354
|
+
resourceKind: 'file',
|
|
355
|
+
resourceId: fileName,
|
|
356
|
+
action: 'read',
|
|
357
|
+
markers: markers,
|
|
358
|
+
});
|
|
359
|
+
// const result = await this._policies.authorizeRequestUsingContext(
|
|
360
|
+
// context.context,
|
|
361
|
+
// {
|
|
362
|
+
// action: 'file.read',
|
|
363
|
+
// ...baseRequest,
|
|
364
|
+
// fileSizeInBytes: fileResult.sizeInBytes,
|
|
365
|
+
// fileMimeType: getType(fileResult.fileName),
|
|
366
|
+
// resourceMarkers: markers,
|
|
367
|
+
// }
|
|
368
|
+
// );
|
|
369
|
+
if (result.success === false) {
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
const policy = context.context.subjectPolicy;
|
|
373
|
+
subjectId = result.user.subjectId;
|
|
374
|
+
if (!subjectId &&
|
|
375
|
+
context.context.userRole === 'none' &&
|
|
376
|
+
policy !== 'subjectless') {
|
|
379
377
|
return {
|
|
380
|
-
success:
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
requestHeaders: readResult.requestHeaders,
|
|
378
|
+
success: false,
|
|
379
|
+
errorCode: 'not_logged_in',
|
|
380
|
+
errorMessage: 'The user must be logged in in order to read files.',
|
|
384
381
|
};
|
|
385
382
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
383
|
+
const recordName = result.recordName;
|
|
384
|
+
const readResult = await this._store.presignFileRead({
|
|
385
|
+
recordName,
|
|
386
|
+
fileName,
|
|
387
|
+
headers: {},
|
|
388
|
+
});
|
|
389
|
+
if (readResult.success === false) {
|
|
391
390
|
return {
|
|
392
391
|
success: false,
|
|
393
|
-
errorCode:
|
|
394
|
-
errorMessage:
|
|
392
|
+
errorCode: readResult.errorCode,
|
|
393
|
+
errorMessage: readResult.errorMessage,
|
|
395
394
|
};
|
|
396
395
|
}
|
|
397
|
-
|
|
396
|
+
return {
|
|
397
|
+
success: true,
|
|
398
|
+
requestUrl: readResult.requestUrl,
|
|
399
|
+
requestMethod: readResult.requestMethod,
|
|
400
|
+
requestHeaders: readResult.requestHeaders,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
catch (err) {
|
|
404
|
+
const span = trace.getActiveSpan();
|
|
405
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
406
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
407
|
+
console.error('[FileRecordsController] An error occurred while reading a file:', err);
|
|
408
|
+
return {
|
|
409
|
+
success: false,
|
|
410
|
+
errorCode: 'server_error',
|
|
411
|
+
errorMessage: 'A server error occurred.',
|
|
412
|
+
};
|
|
413
|
+
}
|
|
398
414
|
}
|
|
399
415
|
/**
|
|
400
416
|
* Attempts to list the files that are available in the given record.
|
|
@@ -403,160 +419,152 @@ export class FileRecordsController {
|
|
|
403
419
|
* @param userId The ID of the user who is retrieving the data. If null, then it is assumed that the user is not logged in.
|
|
404
420
|
* @param instances The instances that are loaded.
|
|
405
421
|
*/
|
|
406
|
-
listFiles(recordKeyOrRecordName, fileName, userId, instances) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
if (!this._store.listUploadedFiles) {
|
|
410
|
-
return {
|
|
411
|
-
success: false,
|
|
412
|
-
errorCode: 'not_supported',
|
|
413
|
-
errorMessage: 'This operation is not supported.',
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
const baseRequest = {
|
|
417
|
-
recordKeyOrRecordName,
|
|
418
|
-
userId: userId,
|
|
419
|
-
instances,
|
|
420
|
-
};
|
|
421
|
-
const context = yield this._policies.constructAuthorizationContext(baseRequest);
|
|
422
|
-
if (context.success === false) {
|
|
423
|
-
return context;
|
|
424
|
-
}
|
|
425
|
-
const authorizeResult = yield this._policies.authorizeUserAndInstances(context.context, {
|
|
426
|
-
userId: userId,
|
|
427
|
-
instances,
|
|
428
|
-
resourceKind: 'file',
|
|
429
|
-
action: 'list',
|
|
430
|
-
markers: [ACCOUNT_MARKER],
|
|
431
|
-
});
|
|
432
|
-
if (authorizeResult.success === false) {
|
|
433
|
-
return authorizeResult;
|
|
434
|
-
}
|
|
435
|
-
const result2 = yield this._store.listUploadedFiles(context.context.recordName, fileName);
|
|
436
|
-
if (result2.success === false) {
|
|
437
|
-
return {
|
|
438
|
-
success: false,
|
|
439
|
-
errorCode: result2.errorCode,
|
|
440
|
-
errorMessage: result2.errorMessage,
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
return {
|
|
444
|
-
success: true,
|
|
445
|
-
recordName: context.context.recordName,
|
|
446
|
-
files: result2.files,
|
|
447
|
-
totalCount: result2.totalCount,
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
catch (err) {
|
|
451
|
-
const span = trace.getActiveSpan();
|
|
452
|
-
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
453
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
454
|
-
console.error('[FileRecordsController] An error occurred while listing files:', err);
|
|
422
|
+
async listFiles(recordKeyOrRecordName, fileName, userId, instances) {
|
|
423
|
+
try {
|
|
424
|
+
if (!this._store.listUploadedFiles) {
|
|
455
425
|
return {
|
|
456
426
|
success: false,
|
|
457
|
-
errorCode: '
|
|
458
|
-
errorMessage: '
|
|
427
|
+
errorCode: 'not_supported',
|
|
428
|
+
errorMessage: 'This operation is not supported.',
|
|
459
429
|
};
|
|
460
430
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const existingMarkers = getRootMarkersOrDefault(fileResult.markers);
|
|
480
|
-
const resourceMarkers = markers !== null && markers !== void 0 ? markers : existingMarkers;
|
|
481
|
-
const result = yield this._policies.authorizeUserAndInstancesForResources(context.context, {
|
|
482
|
-
userId: subjectId,
|
|
483
|
-
instances: instances,
|
|
484
|
-
resources: [
|
|
485
|
-
{
|
|
486
|
-
resourceKind: 'file',
|
|
487
|
-
resourceId: fileName,
|
|
488
|
-
action: 'update',
|
|
489
|
-
markers: resourceMarkers,
|
|
490
|
-
},
|
|
491
|
-
...getMarkerResourcesForUpdate(existingMarkers, markers),
|
|
492
|
-
],
|
|
493
|
-
});
|
|
494
|
-
if (result.success === false) {
|
|
495
|
-
return result;
|
|
496
|
-
}
|
|
497
|
-
subjectId = context.context.userId;
|
|
498
|
-
const updateResult = yield this._store.updateFileRecord(result.recordName, fileName, resourceMarkers);
|
|
499
|
-
if (updateResult.success === false) {
|
|
500
|
-
return updateResult;
|
|
501
|
-
}
|
|
502
|
-
return {
|
|
503
|
-
success: true,
|
|
504
|
-
};
|
|
431
|
+
const baseRequest = {
|
|
432
|
+
recordKeyOrRecordName,
|
|
433
|
+
userId: userId,
|
|
434
|
+
instances,
|
|
435
|
+
};
|
|
436
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
437
|
+
if (context.success === false) {
|
|
438
|
+
return context;
|
|
439
|
+
}
|
|
440
|
+
const authorizeResult = await this._policies.authorizeUserAndInstances(context.context, {
|
|
441
|
+
userId: userId,
|
|
442
|
+
instances,
|
|
443
|
+
resourceKind: 'file',
|
|
444
|
+
action: 'list',
|
|
445
|
+
markers: [ACCOUNT_MARKER],
|
|
446
|
+
});
|
|
447
|
+
if (authorizeResult.success === false) {
|
|
448
|
+
return authorizeResult;
|
|
505
449
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
509
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
510
|
-
console.error('[FileRecordsController] An error occurred while reading a file:', err);
|
|
450
|
+
const result2 = await this._store.listUploadedFiles(context.context.recordName, fileName);
|
|
451
|
+
if (result2.success === false) {
|
|
511
452
|
return {
|
|
512
453
|
success: false,
|
|
513
|
-
errorCode:
|
|
514
|
-
errorMessage:
|
|
454
|
+
errorCode: result2.errorCode,
|
|
455
|
+
errorMessage: result2.errorMessage,
|
|
515
456
|
};
|
|
516
457
|
}
|
|
517
|
-
|
|
458
|
+
return {
|
|
459
|
+
success: true,
|
|
460
|
+
recordName: context.context.recordName,
|
|
461
|
+
files: result2.files,
|
|
462
|
+
totalCount: result2.totalCount,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
catch (err) {
|
|
466
|
+
const span = trace.getActiveSpan();
|
|
467
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
468
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
469
|
+
console.error('[FileRecordsController] An error occurred while listing files:', err);
|
|
470
|
+
return {
|
|
471
|
+
success: false,
|
|
472
|
+
errorCode: 'server_error',
|
|
473
|
+
errorMessage: 'A server error occurred.',
|
|
474
|
+
};
|
|
475
|
+
}
|
|
518
476
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
477
|
+
async updateFile(recordKeyOrRecordName, fileName, subjectId, markers, instances) {
|
|
478
|
+
try {
|
|
479
|
+
const baseRequest = {
|
|
480
|
+
recordKeyOrRecordName,
|
|
481
|
+
userId: subjectId,
|
|
482
|
+
instances,
|
|
483
|
+
};
|
|
484
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
485
|
+
if (context.success === false) {
|
|
486
|
+
return context;
|
|
529
487
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
534
|
-
console.error('[FileRecordsController] An error occurred while marking a file as uploaded:', err);
|
|
535
|
-
return {
|
|
536
|
-
success: false,
|
|
537
|
-
errorCode: 'server_error',
|
|
538
|
-
errorMessage: 'A server error occurred.',
|
|
539
|
-
};
|
|
488
|
+
const fileResult = await this._store.getFileRecord(context.context.recordName, fileName);
|
|
489
|
+
if (fileResult.success === false) {
|
|
490
|
+
return fileResult;
|
|
540
491
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
492
|
+
const existingMarkers = getRootMarkersOrDefault(fileResult.markers);
|
|
493
|
+
const resourceMarkers = markers !== null && markers !== void 0 ? markers : existingMarkers;
|
|
494
|
+
const result = await this._policies.authorizeUserAndInstancesForResources(context.context, {
|
|
495
|
+
userId: subjectId,
|
|
496
|
+
instances: instances,
|
|
497
|
+
resources: [
|
|
498
|
+
{
|
|
499
|
+
resourceKind: 'file',
|
|
500
|
+
resourceId: fileName,
|
|
501
|
+
action: 'update',
|
|
502
|
+
markers: resourceMarkers,
|
|
503
|
+
},
|
|
504
|
+
...getMarkerResourcesForUpdate(existingMarkers, markers),
|
|
505
|
+
],
|
|
506
|
+
});
|
|
507
|
+
if (result.success === false) {
|
|
508
|
+
return result;
|
|
547
509
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
console.error('[FileRecordsController] An error occurred while getting a file name:', err);
|
|
553
|
-
return {
|
|
554
|
-
success: false,
|
|
555
|
-
errorCode: 'server_error',
|
|
556
|
-
errorMessage: 'A server error occurred.',
|
|
557
|
-
};
|
|
510
|
+
subjectId = context.context.userId;
|
|
511
|
+
const updateResult = await this._store.updateFileRecord(result.recordName, fileName, resourceMarkers);
|
|
512
|
+
if (updateResult.success === false) {
|
|
513
|
+
return updateResult;
|
|
558
514
|
}
|
|
559
|
-
|
|
515
|
+
return {
|
|
516
|
+
success: true,
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
catch (err) {
|
|
520
|
+
const span = trace.getActiveSpan();
|
|
521
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
522
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
523
|
+
console.error('[FileRecordsController] An error occurred while reading a file:', err);
|
|
524
|
+
return {
|
|
525
|
+
success: false,
|
|
526
|
+
errorCode: 'server_error',
|
|
527
|
+
errorMessage: 'A server error occurred.',
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
async markFileAsUploaded(recordName, fileName) {
|
|
532
|
+
try {
|
|
533
|
+
const result = await this._store.setFileRecordAsUploaded(recordName, fileName);
|
|
534
|
+
if (result.success === false) {
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
success: true,
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
catch (err) {
|
|
542
|
+
const span = trace.getActiveSpan();
|
|
543
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
544
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
545
|
+
console.error('[FileRecordsController] An error occurred while marking a file as uploaded:', err);
|
|
546
|
+
return {
|
|
547
|
+
success: false,
|
|
548
|
+
errorCode: 'server_error',
|
|
549
|
+
errorMessage: 'A server error occurred.',
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
async getFileNameFromUrl(fileUrl) {
|
|
554
|
+
try {
|
|
555
|
+
return await this._store.getFileNameFromUrl(fileUrl);
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
const span = trace.getActiveSpan();
|
|
559
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
560
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
561
|
+
console.error('[FileRecordsController] An error occurred while getting a file name:', err);
|
|
562
|
+
return {
|
|
563
|
+
success: false,
|
|
564
|
+
errorCode: 'server_error',
|
|
565
|
+
errorMessage: 'A server error occurred.',
|
|
566
|
+
};
|
|
567
|
+
}
|
|
560
568
|
}
|
|
561
569
|
getAllowedUploadHeaders() {
|
|
562
570
|
return this._store.getAllowedUploadHeaders();
|