Skip to content

Commit

Permalink
fix: Add Size to upload URL
Browse files Browse the repository at this point in the history
Like that, cozy-stack is able to cut the connexion before the end if
there is no space left on the device.
  • Loading branch information
Crash-- committed Aug 1, 2023
1 parent 321c68d commit 2668ada
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/app/domain/backup/models/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Media {
creationDate: number
modificationDate: number
albums: Album[]
fileSize: number | null
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/app/domain/backup/services/getMedias.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('formatMediasFromPhotoIdentifier', () => {
group_name: 'Pictures',
image: {
extension: 'jpg',
fileSize: null,
fileSize: 1234,
filename: 'IMG_20230519_204453.jpg',
height: null,
orientation: null,
Expand All @@ -70,6 +70,7 @@ describe('formatMediasFromPhotoIdentifier', () => {
remotePath: '/Pictures',
type: 'image',
mimeType: 'image/jpeg',
fileSize: 1234,
creationDate: 1684521894234,
modificationDate: 1684521894000,
albums: [{ name: 'Pictures' }]
Expand All @@ -85,7 +86,7 @@ describe('formatMediasFromPhotoIdentifier', () => {
group_name: ['Pictures'],
image: {
extension: 'heic',
fileSize: null,
fileSize: 1234,
filename: 'IMG_0744.HEIC',
height: null,
playableDuration: null,
Expand All @@ -110,6 +111,7 @@ describe('formatMediasFromPhotoIdentifier', () => {
path: 'ph://5FD84686-207F-40F1-BCE8-3A837275B0E3/L0/001',
remotePath: '/',
type: 'image',
fileSize: 1234,
mimeType: undefined,
creationDate: 1682604478599,
modificationDate: 1688756699463.186,
Expand All @@ -126,7 +128,7 @@ describe('formatMediasFromPhotoIdentifier', () => {
group_name: ['Pictures'],
image: {
extension: 'heic',
fileSize: null,
fileSize: 1234,
filename: 'IMG_0744.HEIC',
height: null,
playableDuration: null,
Expand Down Expand Up @@ -164,6 +166,7 @@ describe('formatMediasFromPhotoIdentifier', () => {
type: 'image',
subType: 'PhotoLive',
mimeType: undefined,
fileSize: 1234,
creationDate: 1682604478599,
modificationDate: 1688756699463.186,
albums: [{ name: 'Pictures' }]
Expand Down
14 changes: 8 additions & 6 deletions src/app/domain/backup/services/getMedias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ const getPhotoIdentifiersPage = async (
const photoIdentifiersPage = await CameraRoll.getPhotos({
first: MEDIAS_BY_PAGE,
after: after,
include: ['filename', 'fileExtension']
include: ['filename', 'fileExtension', 'fileSize']
})

return photoIdentifiersPage
}

Expand Down Expand Up @@ -72,7 +71,7 @@ export const formatMediasFromPhotoIdentifier = (
): Media[] => {
const {
node: {
image: { filename, uri },
image: { filename, uri, fileSize },
type,
subTypes,
timestamp,
Expand All @@ -94,7 +93,8 @@ export const formatMediasFromPhotoIdentifier = (
subType: 'PhotoLive',
creationDate: timestamp * 1000,
modificationDate: modificationTimestamp * 1000,
albums
albums,
fileSize: null
},
{
name: filename,
Expand All @@ -104,7 +104,8 @@ export const formatMediasFromPhotoIdentifier = (
subType: 'PhotoLive',
creationDate: timestamp * 1000,
modificationDate: modificationTimestamp * 1000,
albums
albums,
fileSize
}
]
}
Expand All @@ -118,7 +119,8 @@ export const formatMediasFromPhotoIdentifier = (
mimeType: Platform.OS == 'android' ? type : undefined,
creationDate: timestamp * 1000,
modificationDate: modificationTimestamp * 1000,
albums
albums,
fileSize
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/domain/backup/services/uploadMedias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export const uploadMedias = async (
metadataId,
mediaToUpload
)

const { data: documentCreated } = await uploadMedia(
client,
uploadUrl,
Expand Down Expand Up @@ -240,6 +239,9 @@ const getUploadUrl = (
toURL.searchParams.append('CreatedAt', createdAt)
toURL.searchParams.append('UpdatedAt', modifiedAt)
toURL.searchParams.append('MetadataID', metadataId)
if (media.fileSize !== null) {
toURL.searchParams.append('Size', media.fileSize.toString())
}

return toURL.toString()
}

0 comments on commit 2668ada

Please sign in to comment.