generated from krauters/typescript-core
-
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.
- Loading branch information
1 parent
52d2bf5
commit 3143822
Showing
3 changed files
with
70 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 { init, searchAssets } from '@immich/sdk' | ||
|
||
const apiKey = process.env.IMMICH_API_KEY | ||
const baseUrl = process.env.IMMICH_BASE_URL | ||
|
||
if (!apiKey || !baseUrl) { | ||
throw new Error('Missing IMMICH_API_KEY or IMMICH_BASE_URL environment variables') | ||
} | ||
|
||
init({ apiKey, baseUrl }) | ||
|
||
async function* getMotionPhotoIds(): AsyncGenerator<string[]> { | ||
let nextPage: string | null = '1' | ||
let totalFound = 0 | ||
|
||
do { | ||
try { | ||
const response = await searchAssets({ | ||
metadataSearchDto: { isMotion: true, page: parseInt(nextPage) }, | ||
}) | ||
|
||
const assets = response.assets.items | ||
if (assets && assets.length > 0) { | ||
const motionPhotoIds = assets.map((asset: { id: string }) => asset.id) | ||
totalFound += motionPhotoIds.length | ||
console.log(`Running total of motion photos found [${totalFound}]`) | ||
yield motionPhotoIds | ||
} | ||
|
||
nextPage = response.assets.nextPage | ||
} catch (error) { | ||
console.error(`Failed searching for motion photos with error [${error}]`) | ||
break | ||
} | ||
} while (nextPage) | ||
} | ||
|
||
void (async () => { | ||
console.log('Starting search for motion photos...') | ||
|
||
const startTime = Date.now() | ||
let totalMotionPhotos = 0 | ||
|
||
for await (const motionPhotoIds of getMotionPhotoIds()) { | ||
console.log(`Found [${motionPhotoIds.length}] motion photos in this batch`) | ||
totalMotionPhotos += motionPhotoIds.length | ||
} | ||
|
||
const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(2) | ||
console.log('--- Report ---') | ||
console.log(`Total motion photos found: [${totalMotionPhotos}]`) | ||
console.log(`Elapsed time: [${elapsedTime}] seconds`) | ||
console.log('Search completed successfully') | ||
})() |