Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3348763
D5190.id16956.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D5190.id16956.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 4:00 PM (18 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2570443
Default Alt Text
D5190.id16956.diff (3 KB)
Attached To
Mode
D5190: [lib] Introduce `getUploadIDsFromMediaMessageServerDBContents(...)`
Attached
Detach File
Event Timeline
Log In to Comment