Page MenuHomePhabricator

D5190.diff
No OneTemporary

D5190.diff

diff --git a/keyserver/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js
--- a/keyserver/src/fetchers/upload-fetchers.js
+++ b/keyserver/src/fetchers/upload-fetchers.js
@@ -4,6 +4,7 @@
import type { Media } from 'lib/types/media-types';
import type { MediaMessageServerDBContent } from 'lib/types/messages/media.js';
+import { getUploadIDsFromMediaMessageServerDBContents } from 'lib/types/messages/media.js';
import { ServerError } from 'lib/utils/errors';
import { dbQuery, SQL } from '../database/database';
@@ -119,14 +120,9 @@
viewer: Viewer,
mediaMessageContents: $ReadOnlyArray<MediaMessageServerDBContent>,
): Promise<$ReadOnlyArray<Object>> {
- const uploadIDs = [];
- for (const mediaContent of mediaMessageContents) {
- uploadIDs.push(mediaContent.uploadID);
- if (mediaContent.type === 'video') {
- uploadIDs.push(mediaContent.thumbnailUploadID);
- }
- }
-
+ const uploadIDs = getUploadIDsFromMediaMessageServerDBContents(
+ mediaMessageContents,
+ );
const query = SQL`
SELECT id AS uploadID, secret AS uploadSecret,
type AS uploadType, extra AS uploadExtra
diff --git a/keyserver/src/updaters/upload-updaters.js b/keyserver/src/updaters/upload-updaters.js
--- a/keyserver/src/updaters/upload-updaters.js
+++ b/keyserver/src/updaters/upload-updaters.js
@@ -1,6 +1,7 @@
// @flow
import type { MediaMessageServerDBContent } from 'lib/types/messages/media.js';
+import { getUploadIDsFromMediaMessageServerDBContents } from 'lib/types/messages/media.js';
import { dbQuery, SQL } from '../database/database';
import type { Viewer } from '../session/viewer';
@@ -23,17 +24,13 @@
mediaMessageContents: $ReadOnlyArray<MediaMessageServerDBContent>,
containerID: string,
): Promise<void> {
- const mediaIDs: string[] = [];
- for (const mediaContent of mediaMessageContents) {
- mediaIDs.push(mediaContent.uploadID);
- if (mediaContent.type === 'video') {
- mediaIDs.push(mediaContent.thumbnailUploadID);
- }
- }
+ const uploadIDs = getUploadIDsFromMediaMessageServerDBContents(
+ mediaMessageContents,
+ );
const query = SQL`
UPDATE uploads
SET container = ${containerID}
- WHERE id IN (${mediaIDs}) AND uploader = ${viewer.id} AND container IS NULL
+ WHERE id IN (${uploadIDs}) AND uploader = ${viewer.id} AND container IS NULL
`;
await dbQuery(query);
}
diff --git a/lib/types/messages/media.js b/lib/types/messages/media.js
--- a/lib/types/messages/media.js
+++ b/lib/types/messages/media.js
@@ -37,3 +37,18 @@
+uploadID: string,
+thumbnailUploadID: string,
};
+
+function getUploadIDsFromMediaMessageServerDBContents(
+ mediaMessageContents: $ReadOnlyArray<MediaMessageServerDBContent>,
+): $ReadOnlyArray<string> {
+ const uploadIDs: string[] = [];
+ for (const mediaContent of mediaMessageContents) {
+ uploadIDs.push(mediaContent.uploadID);
+ if (mediaContent.type === 'video') {
+ uploadIDs.push(mediaContent.thumbnailUploadID);
+ }
+ }
+ return uploadIDs;
+}
+
+export { getUploadIDsFromMediaMessageServerDBContents };

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 11:35 AM (19 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2570443
Default Alt Text
D5190.diff (3 KB)

Event Timeline