updated mobile media uploader logic to be more redundant
This commit is contained in:
@@ -137,6 +137,39 @@ export class MobileController {
|
||||
});
|
||||
}
|
||||
|
||||
findMediaAssetByExternalMediaId(
|
||||
fctx: FlowExecCtx,
|
||||
deviceId: number,
|
||||
externalMediaId: string,
|
||||
) {
|
||||
return traceResultAsync({
|
||||
name: "mobile.media.findByExternalId",
|
||||
fctx,
|
||||
attributes: {
|
||||
"app.mobile.device_id": deviceId,
|
||||
"app.mobile.external_media_id": externalMediaId,
|
||||
},
|
||||
fn: () =>
|
||||
this.mobileRepo.findMediaAssetByExternalMediaId(
|
||||
fctx,
|
||||
deviceId,
|
||||
externalMediaId,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
findMediaAssetByHash(fctx: FlowExecCtx, deviceId: number, hash: string) {
|
||||
return traceResultAsync({
|
||||
name: "mobile.media.findByHash",
|
||||
fctx,
|
||||
attributes: {
|
||||
"app.mobile.device_id": deviceId,
|
||||
"app.mobile.media_hash": hash,
|
||||
},
|
||||
fn: () => this.mobileRepo.findMediaAssetByHash(fctx, deviceId, hash),
|
||||
});
|
||||
}
|
||||
|
||||
listDevices(
|
||||
fctx: FlowExecCtx,
|
||||
filters: ListMobileDevicesFilters,
|
||||
|
||||
@@ -424,6 +424,60 @@ export class MobileRepository {
|
||||
);
|
||||
}
|
||||
|
||||
findMediaAssetByExternalMediaId(
|
||||
fctx: FlowExecCtx,
|
||||
deviceId: number,
|
||||
externalMediaId: string,
|
||||
): ResultAsync<{ id: number; fileId: string } | null, Err> {
|
||||
return ResultAsync.fromPromise(
|
||||
this.db
|
||||
.select({
|
||||
id: mobileMediaAsset.id,
|
||||
fileId: mobileMediaAsset.fileId,
|
||||
})
|
||||
.from(mobileMediaAsset)
|
||||
.where(
|
||||
and(
|
||||
eq(mobileMediaAsset.deviceId, deviceId),
|
||||
eq(mobileMediaAsset.externalMediaId, externalMediaId),
|
||||
),
|
||||
)
|
||||
.limit(1),
|
||||
(error) =>
|
||||
mobileErrors.listMediaFailed(
|
||||
fctx,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
),
|
||||
).map((rows) => rows[0] ?? null);
|
||||
}
|
||||
|
||||
findMediaAssetByHash(
|
||||
fctx: FlowExecCtx,
|
||||
deviceId: number,
|
||||
hash: string,
|
||||
): ResultAsync<{ id: number; fileId: string } | null, Err> {
|
||||
return ResultAsync.fromPromise(
|
||||
this.db
|
||||
.select({
|
||||
id: mobileMediaAsset.id,
|
||||
fileId: mobileMediaAsset.fileId,
|
||||
})
|
||||
.from(mobileMediaAsset)
|
||||
.where(
|
||||
and(
|
||||
eq(mobileMediaAsset.deviceId, deviceId),
|
||||
eq(mobileMediaAsset.hash, hash),
|
||||
),
|
||||
)
|
||||
.limit(1),
|
||||
(error) =>
|
||||
mobileErrors.listMediaFailed(
|
||||
fctx,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
),
|
||||
).map((rows) => rows[0] ?? null);
|
||||
}
|
||||
|
||||
listDevices(
|
||||
fctx: FlowExecCtx,
|
||||
filters: ListMobileDevicesFilters,
|
||||
|
||||
@@ -38,6 +38,7 @@ export class R2StorageClient {
|
||||
this.s3Client = new S3Client({
|
||||
region: config.region,
|
||||
endpoint: config.endpoint,
|
||||
forcePathStyle: true,
|
||||
credentials: {
|
||||
accessKeyId: config.accessKey,
|
||||
secretAccessKey: config.secretKey,
|
||||
|
||||
Reference in New Issue
Block a user