forked from OpenBeta/openbeta-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate photo storage to GCloud storage (OpenBeta#273)
* chore: extract & save image width/height during migration * chore: resolve username in the backend instead of frontend * chore: return image metadata to tag queries * chore: climb/area/user profile media share the same type * refactor: embed tags in media object collection * refactor: update find-tags-by-area-id to work with embedded tags * refactor: move leaderboard api to new embedded tags model
- Loading branch information
Showing
29 changed files
with
1,527 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import mongoose from 'mongoose' | ||
|
||
import { MediaObject, EntityTag } from './MediaObjectTypes.js' | ||
import { PointSchema } from './ClimbSchema.js' | ||
|
||
const { Schema } = mongoose | ||
|
||
const UUID_TYPE = { | ||
type: 'object', value: { type: 'Buffer' } | ||
} | ||
|
||
const EntitySchema = new Schema<EntityTag>({ | ||
targetId: { ...UUID_TYPE, index: true }, | ||
climbName: { type: Schema.Types.String }, | ||
areaName: { type: Schema.Types.String, required: true }, | ||
type: { type: Schema.Types.Number, required: true }, | ||
ancestors: { type: Schema.Types.String, required: true, index: true }, | ||
lnglat: { | ||
type: PointSchema, | ||
index: '2dsphere' | ||
} | ||
}, { _id: true }) | ||
|
||
const schema = new Schema<MediaObject>({ | ||
userUuid: { ...UUID_TYPE, index: true }, | ||
mediaUrl: { type: Schema.Types.String, unique: true, index: true }, | ||
width: { type: Schema.Types.Number, required: true }, | ||
height: { type: Schema.Types.Number, required: true }, | ||
size: { type: Schema.Types.Number, required: true }, | ||
format: { type: Schema.Types.String, required: true }, | ||
entityTags: [EntitySchema] | ||
}, { _id: true, timestamps: true }) | ||
|
||
/** | ||
* Additional indices | ||
*/ | ||
schema.index({ | ||
/** | ||
* For filtering media objects with/without tags | ||
*/ | ||
entityTags: 1, | ||
/** | ||
* For sorting media objects by insertion order | ||
*/ | ||
createdAt: -1 // ascending, more recent first | ||
}) | ||
|
||
/** | ||
* Get media object model | ||
* @returns MediaObjectType | ||
*/ | ||
export const getMediaObjectModel = (): mongoose.Model<MediaObject> => { | ||
return mongoose.model('media_objects', schema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ObjectId } from 'mongoose' | ||
import { MUUID } from 'uuid-mongodb' | ||
import { Point } from '@turf/helpers' | ||
|
||
export type ImageFormatType = 'jpeg' | 'png' | 'webp' | 'avif' | ||
|
||
export interface MediaObject { | ||
_id: ObjectId | ||
userUuid: MUUID | ||
mediaUrl: string | ||
width: number | ||
height: number | ||
format: ImageFormatType | ||
createdAt: Date | ||
size: number | ||
entityTags: EntityTag[] | ||
} | ||
|
||
export interface EntityTag { | ||
_id: ObjectId | ||
targetId: MUUID | ||
type: number | ||
ancestors: string | ||
climbName?: string | ||
areaName: string | ||
lnglat: Point | ||
} | ||
|
||
export interface MediaByUsers { | ||
username: string | ||
userUuid: MUUID | ||
mediaWithTags: MediaObject[] | ||
} | ||
export interface MediaForFeedInput { | ||
uuidStr?: string | ||
maxUsers?: number | ||
maxFiles?: number | ||
includesNoEntityTags?: boolean | ||
} | ||
|
||
export interface TagByUser { | ||
username?: string | ||
userUuid: MUUID | ||
total: number | ||
} | ||
|
||
export interface AllTimeTagStats { | ||
totalMediaWithTags: number | ||
byUsers: TagByUser[] | ||
} | ||
export interface TagsLeaderboardType { | ||
allTime: AllTimeTagStats | ||
} | ||
|
||
export interface UserMediaQueryInput { | ||
userUuid: string | ||
maxFiles?: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AuthorMetadata } from '../../types' | ||
|
||
export const getAuthorMetadataFromBaseNode = ({ updatedAt, updatedBy, createdAt, createdBy }: AuthorMetadata): AuthorMetadata => ({ | ||
updatedAt, | ||
updatedBy, | ||
createdAt, | ||
createdBy | ||
}) |
Oops, something went wrong.