Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>sutne - Personal API</title>
</head>
Expand Down
2,433 changes: 1,161 additions & 1,272 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"devDependencies": {
"@biomejs/biome": "2.3.13",
"@types/node": "^25.2.0",
"@vercel/node": "^5.5.28",
"psn-api": "^2.17.0",
"typescript": "^5.9.3",
"vercel": "^50.9.6"
"@biomejs/biome": "2.4.12",
"@types/node": "^25.6.0",
"@vercel/node": "^5.7.6",
"psn-api": "^2.18.0",
"typescript": "^6.0.2",
"vercel": "^51.3.0"
}
}
10 changes: 7 additions & 3 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ export async function GET(url: string, args: get_args = {}) {
* @param url Root URL
* @param args `{ headers: {}, body: {} }`
*/
export async function POST<T>(url: string, args: post_args = {}): Promise<T> {
export async function POST<T>(
url: string,
args: post_args = {},
): Promise<T | undefined> {
// Convert body to correct format
const content = convert(args.body, args.headers?.['Content-Type']);

// Perform post request
return await MyFetch(url, {
return await MyFetch<T>(url, {
method: 'POST',
headers: { ...args.headers },
body: content,
Expand All @@ -41,7 +44,7 @@ export async function POST<T>(url: string, args: post_args = {}): Promise<T> {
* everywhere.
*
*/
async function MyFetch<T>(url: string, args: object): Promise<T> {
async function MyFetch<T>(url: string, args: object): Promise<T | undefined> {
let error = {};
try {
// Perform fetch request
Expand All @@ -65,5 +68,6 @@ async function MyFetch<T>(url: string, args: object): Promise<T> {
args,
error,
});
return undefined;
}
}
2 changes: 1 addition & 1 deletion src/playstation/get-all-trophies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function getAllTrophies(): Promise<CompleteTrophy[]> {
trophyTitle.npCommunicationId,
platform(trophyTitle.trophyTitlePlatform),
);
const trophies: CompleteTrophy[] = groups.reduce(
const trophies: CompleteTrophy[] = groups.reduce<CompleteTrophy[]>(
(trophies, group) =>
trophies.concat(
group.trophies.map((trophy) => {
Expand Down
6 changes: 4 additions & 2 deletions src/playstation/get-trophies-for-single-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ function mergeGroups(a: TrophyGroup, b: TrophyGroup): TrophyGroup {
if (hasAllBronze && hasAllSilver && hasAllGold) {
merged.earnedCount.platinum = 1;
const platinum = merged.trophies.find((t) => t.type === 'platinum');
platinum.isEarned = true;
platinum.earnedAt = merged.trophies.map((t) => t.earnedAt).reduce(latestDate);
if (platinum) {
platinum.isEarned = true;
platinum.earnedAt = merged.trophies.map((t) => t.earnedAt).reduce(latestDate);
}
}
}
merged.progress = getTrophyCountProgress(merged.earnedCount, merged.trophyCount);
Expand Down
4 changes: 3 additions & 1 deletion src/playstation/util/api/trophy-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export async function getTrophyGroups(id: string, platform: Platform) {
}
}

if (trophy.isEarned) groups[groupIndex].earnedCount[trophy.type] += 1;
if (trophy.isEarned && trophy.type) {
groups[groupIndex].earnedCount[trophy.type] += 1;
}
// Add trophy and its info to list
groups[groupIndex].trophies.push(trophy as Trophy);
}
Expand Down
2 changes: 1 addition & 1 deletion src/playstation/util/trophy-calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function pointsToNextLevel(currentLevel: number): number {

export function getTrophyPoints(counts: TrophyCount): number {
return Object.entries(counts).reduce((sum, trophy) => {
const [type, count] = trophy;
const [type, count] = trophy as [keyof typeof TrophyPoints, number];
return sum + TrophyPoints[type] * count;
}, 0);
}
Expand Down
13 changes: 8 additions & 5 deletions src/playstation/util/trophy-sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ export function compareTrophyProgress(a: Trophy, b: Trophy): number {
return progressDiff;
}

type TrophyComparator = { func: (a: Trophy, b: Trophy) => number; reverse?: boolean };
type TrophyComparator<T extends Trophy> = {
func: (a: T, b: T) => number;
reverse?: boolean;
};
/** sort trophies based on custom set of comparators performed in order. */
export function compareTrophies(
a: Trophy,
b: Trophy,
comparators: TrophyComparator[],
export function compareTrophies<T extends Trophy>(
a: T,
b: T,
comparators: TrophyComparator<T>[],
): number {
for (const { func, reverse } of comparators) {
const diff = func(a, b);
Expand Down