Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3396407
D7808.id26592.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D7808.id26592.diff
View Options
diff --git a/keyserver/src/uploads/uploads.js b/keyserver/src/uploads/uploads.js
--- a/keyserver/src/uploads/uploads.js
+++ b/keyserver/src/uploads/uploads.js
@@ -4,16 +4,17 @@
import invariant from 'invariant';
import multer from 'multer';
import { Readable } from 'stream';
-import t from 'tcomb';
+import t, { type TInterface } from 'tcomb';
-import type {
- UploadMediaMetadataRequest,
- UploadMultimediaResult,
- UploadDeletionRequest,
- Dimensions,
+import {
+ type UploadMediaMetadataRequest,
+ type UploadMultimediaResult,
+ uploadMultimediaResultValidator,
+ type UploadDeletionRequest,
+ type Dimensions,
} from 'lib/types/media-types.js';
import { ServerError } from 'lib/utils/errors.js';
-import { tShape } from 'lib/utils/validation-utils.js';
+import { tShape, tID } from 'lib/utils/validation-utils.js';
import { getMediaType, validateAndConvert } from './media-utils.js';
import type { UploadInput } from '../creators/upload-creator.js';
@@ -26,7 +27,7 @@
} from '../fetchers/upload-fetchers.js';
import type { MulterRequest } from '../responders/handlers.js';
import type { Viewer } from '../session/viewer.js';
-import { validateInput } from '../utils/validation-utils.js';
+import { validateInput, validateOutput } from '../utils/validation-utils.js';
const upload = multer();
const multerProcessor: Middleware<> = upload.array('multimedia');
@@ -34,6 +35,10 @@
type MultimediaUploadResult = {
results: UploadMultimediaResult[],
};
+const MultimediaUploadResultValidator = tShape<MultimediaUploadResult>({
+ results: t.list(uploadMultimediaResultValidator),
+});
+
async function multimediaUploadResponder(
viewer: Viewer,
req: MulterRequest,
@@ -91,10 +96,16 @@
throw new ServerError('invalid_parameters');
}
const results = await createUploads(viewer, uploadInfos);
- return { results };
+ return validateOutput(
+ viewer.platformDetails,
+ MultimediaUploadResultValidator,
+ {
+ results,
+ },
+ );
}
-const uploadMediaMetadataInputValidator = tShape({
+const uploadMediaMetadataInputValidator = tShape<UploadMediaMetadataRequest>({
filename: t.String,
width: t.Number,
height: t.Number,
@@ -106,10 +117,13 @@
async function uploadMediaMetadataResponder(
viewer: Viewer,
- input: any,
+ input: mixed,
): Promise<UploadMultimediaResult> {
- const request: UploadMediaMetadataRequest = input;
- await validateInput(viewer, uploadMediaMetadataInputValidator, input);
+ const request = await validateInput(
+ viewer,
+ uploadMediaMetadataInputValidator,
+ input,
+ );
const mediaType = getMediaType(request.mimeType);
if (!mediaType) {
@@ -129,7 +143,11 @@
};
const [result] = await createUploads(viewer, [uploadInfo]);
- return result;
+ return validateOutput(
+ viewer.platformDetails,
+ uploadMultimediaResultValidator,
+ result,
+ );
}
async function uploadDownloadResponder(
@@ -198,11 +216,20 @@
}
}
+const uploadDeletionRequestInputValidator: TInterface<UploadDeletionRequest> =
+ tShape<UploadDeletionRequest>({
+ id: tID,
+ });
async function uploadDeletionResponder(
viewer: Viewer,
- request: UploadDeletionRequest,
+ input: mixed,
): Promise<void> {
- const { id } = request;
+ const { id } = await validateInput(
+ viewer,
+ uploadDeletionRequestInputValidator,
+ input,
+ );
+
await deleteUpload(viewer, id);
}
diff --git a/lib/types/media-types.js b/lib/types/media-types.js
--- a/lib/types/media-types.js
+++ b/lib/types/media-types.js
@@ -17,6 +17,7 @@
});
export type MediaType = 'photo' | 'video';
+const mediaTypeValidator = t.enums.of(['photo', 'video']);
export type EncryptedMediaType = 'encrypted_photo' | 'encrypted_video';
@@ -64,6 +65,14 @@
+mediaType: MediaType,
+loop: boolean,
};
+export const uploadMultimediaResultValidator: TInterface<UploadMultimediaResult> =
+ tShape<UploadMultimediaResult>({
+ id: tID,
+ uri: t.String,
+ dimensions: dimensionsValidator,
+ mediaType: mediaTypeValidator,
+ loop: t.Boolean,
+ });
export type UpdateMultimediaMessageMediaPayload = {
+messageID: string,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 2, 12:09 PM (19 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2607551
Default Alt Text
D7808.id26592.diff (4 KB)
Attached To
Mode
D7808: [keyserver] Convert upload responders
Attached
Detach File
Event Timeline
Log In to Comment