-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Add ability to hide unreleased items (#1)
* Add: Add ability to hide unreleased items * Fix: Fix lint failures * Refactor: Extract into variable * Code: level -> item (I forgot to change) * Refactor: More extracting * Fix: Reverse publishedAt * Code: serverConfigurations -> serverOptions * Fix: Return item if it's item * Fix: Hide levels in playlist details * Fix: Fix some code issue * Refactor: Extract into spoiler.ts * Delete: Delete unnecessary conversion
- Loading branch information
1 parent
87aaa2a
commit af35654
Showing
14 changed files
with
129 additions
and
27 deletions.
There are no files selected for viewing
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
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
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,15 @@ | ||
import { ServerOptionsModel } from '@sonolus/express' | ||
|
||
export const serverOptions = { | ||
spoilers: { | ||
type: 'toggle', | ||
name: { | ||
en: 'Spoilers', | ||
}, | ||
def: false, | ||
description: { | ||
en: 'Whether to show unreleased items.', | ||
}, | ||
required: false, | ||
}, | ||
} as const satisfies ServerOptionsModel |
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
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
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
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
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,39 @@ | ||
import { PlaylistItemModel } from '@sonolus/express' | ||
import { sonolus } from '../index.js' | ||
|
||
export const hideSpoilers = <T extends { meta: { publishedAt: number } }>( | ||
passThrough: boolean, | ||
items: T[], | ||
): T[] => { | ||
if (passThrough) { | ||
return items | ||
} | ||
return items.filter((item) => item.meta.publishedAt <= Date.now()) | ||
} | ||
|
||
export const hideSpoilersFromPlaylist = ( | ||
passThrough: boolean, | ||
playlist: PlaylistItemModel, | ||
): PlaylistItemModel => { | ||
if (passThrough) { | ||
return playlist | ||
} | ||
return { | ||
...playlist, | ||
levels: hideSpoilers( | ||
false, | ||
playlist.levels.map((levelNameOrItem) => { | ||
if (typeof levelNameOrItem === 'object') return levelNameOrItem | ||
const level = sonolus.level.items.find((level) => level.name === levelNameOrItem) | ||
if (!level) throw new Error(`Level not found: ${levelNameOrItem}`) | ||
return level | ||
}), | ||
), | ||
} | ||
} | ||
|
||
export const hideSpoilersFromPlaylists = ( | ||
passThrough: boolean, | ||
playlists: PlaylistItemModel[], | ||
): PlaylistItemModel[] => | ||
playlists.map((playlist) => hideSpoilersFromPlaylist(passThrough, playlist)) |