Skip to content

Commit

Permalink
Merge branch 'feature/remove-four-images-priority' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhykos committed Dec 26, 2024
2 parents 5c3d26c + 580e69a commit ea7d9c8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 270 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
<a href="#how-to-use">How To Use</a> •
<a href="#contributing">Contributing</a> •
<a href="#credits">Credits</a> •
<a href="#authors">Authors</a> •
<a href="#license">License</a> •
<a href="#projects-using-autophoto">Projects using autophoto</a>
<a href="#projects-using-autophoto">Projects using autophoto</a> •
<a href="#changelog">Changelog</a>
</p>

![bluesky](doc/bluesky-post.webp)
Expand All @@ -26,7 +28,7 @@

* Pre-scan your directory for photos
- Photos are detected by a path pattern
- Check all detected photos if they are valid
- Check all detected photos if they are valid (for instance BlueSky has size limitations)
* Scan your directory for photos
- For now only suppose to work with video game screenshots
- Photos are detected by a path pattern
Expand Down Expand Up @@ -246,3 +248,10 @@ the domains, the performance, etc. So, if you want to help me, I will be happy t
> [zhykos.fr](https://www.zhykos.fr) &nbsp;&middot;&nbsp;
> GitHub [@zhykos](https://github.com/Zhykos) &nbsp;&middot;&nbsp;
> Bluesky [@zhykos](https://bsky.app/profile/zhykos.bsky.social)

---

## Changelog

* 2.1
- Remove the pick priority of directories which have at least 4 photos to publish
36 changes: 8 additions & 28 deletions src/picker/service/PickerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,7 @@ export class PickerService {
return undefined;
}

const possibilitiesPriority: UnpublishedVideoGamesScreenshot[] =
unpublishedVideoGamesScreenshots.filter(
(screenshot) => screenshot.images.length >= 4,
);

if (possibilitiesPriority.length > 0) {
return this.pickScreenshotsToShare(possibilitiesPriority);
}

const mapByLength = new Map<number, UnpublishedVideoGamesScreenshot[]>();
for (const screenshot of unpublishedVideoGamesScreenshots) {
const length: number = screenshot.images.length;
if (!mapByLength.has(length)) {
mapByLength.set(length, []);
}
mapByLength.get(length)?.push(screenshot);
}
return this.pickScreenshotsToShare(
mapByLength.get(3) ??
mapByLength.get(2) ??
(mapByLength.get(1) as UnpublishedVideoGamesScreenshot[]),
);
return this.pickScreenshotsToShare(unpublishedVideoGamesScreenshots);
}

private pickScreenshotsToShare(
Expand All @@ -67,18 +46,19 @@ export class PickerService {
private async getUnpublishedVideoGamesScreenshots(): Promise<
UnpublishedVideoGamesScreenshot[]
> {
const unpublishedScreenshotRelations: UnpublishedVideoGameScreenshotRelation[] =
await this.relationRepository.getUnpublishedVideoGameRelations();
const unpublishedScreenshotRelations:
UnpublishedVideoGameScreenshotRelation[] = await this.relationRepository
.getUnpublishedVideoGameRelations();
const unpublishedVideoGamesIDs: string[] = distinct(
unpublishedScreenshotRelations.map((rel) => rel.videoGameID),
);
const unpublishedVideoGames: VideoGame[] =
await this.videoGameRepository.getVideoGames(unpublishedVideoGamesIDs);
const unpublishedVideoGames: VideoGame[] = await this.videoGameRepository
.getVideoGames(unpublishedVideoGamesIDs);
const unpublishedImagesIDs: string[] = distinct(
unpublishedScreenshotRelations.map((rel) => rel.imageID),
);
const unpublishedImages: Image[] =
await this.imageRepository.getVideoGameScreenshots(unpublishedImagesIDs);
const unpublishedImages: Image[] = await this.imageRepository
.getVideoGameScreenshots(unpublishedImagesIDs);
return UnpublishedVideoGamesScreenshot.buildAll(
unpublishedScreenshotRelations,
unpublishedVideoGames,
Expand Down
22 changes: 13 additions & 9 deletions test/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { assertEquals } from "@std/assert";
import { assertNotEquals } from "@std/assert/not-equals";
import {
assert,
assertEquals,
assertMatch,
assertNotEquals,
} from "@std/assert";
import {
afterAll,
beforeAll,
Expand Down Expand Up @@ -78,14 +82,14 @@ describe("main", () => {
]);

assertNotEquals(mockedBlueskyServer.lastRecord, undefined);
assertEquals(
mockedBlueskyServer.lastRecord?.text,
'Screenshots from video game "80\'s Overdrive" (2017) taken on Nintendo Switch',
assertMatch(
mockedBlueskyServer.lastRecord?.text ?? "",
/^Screenshots? from video game ".+" \(\d+\) taken on .+$/,
);
assertEquals(mockedBlueskyServer.lastRecord?.embed.images.length, 4);
assertEquals(
mockedBlueskyServer.lastRecord?.embed.images[0].alt,
"Screenshot from video game 80's Overdrive (no more details given by the bot)",
assert((mockedBlueskyServer.lastRecord?.embed.images.length ?? 0) > 0);
assertMatch(
mockedBlueskyServer.lastRecord?.embed.images[0].alt ?? "",
/^Screenshot from video game .+ \(no more details given by the bot\)$/,
);
assertNotEquals(
mockedBlueskyServer.lastRecord?.embed.images[0].image,
Expand Down
Loading

0 comments on commit ea7d9c8

Please sign in to comment.