diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2023-10-21 18:41:12 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-21 18:41:12 +0900 |
| commit | f51bca41c5f59f9ffce346a3ec32badaf1ccda31 (patch) | |
| tree | b5799527c2d3602da3592f7d6c1b65bb6ac8922c /packages/frontend/src/scripts/install-theme.ts | |
| parent | すべてのフォロー中の人のwithRepliesを変える機能 (#12049) (diff) | |
| download | misskey-f51bca41c5f59f9ffce346a3ec32badaf1ccda31.tar.gz misskey-f51bca41c5f59f9ffce346a3ec32badaf1ccda31.tar.bz2 misskey-f51bca41c5f59f9ffce346a3ec32badaf1ccda31.zip | |
Feat: 外部サイトからテーマ・プラグインのインストールができるように (#12034)
* Feat: 外部サイトからテーマ・プラグインのインストールができるように
* Update Changelog
* Change Changelog
* Remove unnecessary imports
* Update fetch-external-resources.ts
* Update CHANGELOG.md
* Update CHANGELOG.md
Diffstat (limited to 'packages/frontend/src/scripts/install-theme.ts')
| -rw-r--r-- | packages/frontend/src/scripts/install-theme.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/install-theme.ts b/packages/frontend/src/scripts/install-theme.ts new file mode 100644 index 0000000000..394b642bf4 --- /dev/null +++ b/packages/frontend/src/scripts/install-theme.ts @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: syuilo and other misskey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import JSON5 from 'json5'; +import { addTheme, getThemes } from '@/theme-store.js'; +import { Theme, applyTheme, validateTheme } from '@/scripts/theme.js'; + +export function parseThemeCode(code: string): Theme { + let theme; + + try { + theme = JSON5.parse(code); + } catch (err) { + throw new Error('Failed to parse theme json'); + } + if (!validateTheme(theme)) { + throw new Error('This theme is invaild'); + } + if (getThemes().some(t => t.id === theme.id)) { + throw new Error('This theme is already installed'); + } + + return theme; +} + +export function previewTheme(code: string): void { + const theme = parseThemeCode(code); + if (theme) applyTheme(theme, false); +} + +export async function installTheme(code: string): Promise<void> { + const theme = parseThemeCode(code); + if (!theme) return; + await addTheme(theme); +} |