Added theme management apis in adminX

refs https://github.com/TryGhost/Team/issues/3432
This commit is contained in:
Rishabh 2023-06-13 13:24:47 +05:30
parent 778e9a5f96
commit 5cc1c43257
2 changed files with 54 additions and 1 deletions

View File

@ -126,3 +126,14 @@ export type CustomThemeSetting = CustomThemeSettingData & {
// homepage and post are the only two groups we handle, but technically theme authors can put other things in package.json
group?: 'homepage' | 'post' | string
}
export type Theme = {
active: boolean;
name: string;
package: {
name?: string;
description?: string;
version?: string;
};
templates?: string[];
}

View File

@ -1,4 +1,4 @@
import {CustomThemeSetting, Label, Offer, Post, Setting, SiteData, Tier, User, UserRole} from '../types/api';
import {CustomThemeSetting, Label, Offer, Post, Setting, SiteData, Theme, Tier, User, UserRole} from '../types/api';
import {getGhostPaths} from './helpers';
interface Meta {
@ -90,6 +90,10 @@ export interface PasswordUpdateResponseType {
}];
}
export interface ThemesResponseType {
themes: Theme[];
}
interface RequestOptions {
method?: string;
body?: string | FormData;
@ -160,6 +164,12 @@ interface API {
offers: {
browse: () => Promise<OffersResponseType>
};
themes: {
browse: () => Promise<ThemesResponseType>;
activate: (themeName: string) => Promise<ThemesResponseType>;
delete: (themeName: string) => Promise<void>;
upload: ({file}: {file: File}) => Promise<ThemesResponseType>;
};
}
interface GhostApiOptions {
@ -386,6 +396,38 @@ function setupGhostApi({ghostVersion}: GhostApiOptions): API {
const data: OffersResponseType = await response.json();
return data;
}
},
themes: {
browse: async () => {
const response = await fetcher('/themes/');
const data: ThemesResponseType = await response.json();
return data;
},
activate: async (themeName: string) => {
const response = await fetcher(`/themes/${themeName}/activate/`, {
method: 'PUT'
});
const data: ThemesResponseType = await response.json();
return data;
},
delete: async (themeName: string) => {
await fetcher(`/themes/${themeName}/`, {
method: 'DELETE'
});
return;
},
upload: async ({file}: {file: File}) => {
const formData = new FormData();
formData.append('file', file);
const response = await fetcher(`/themes/upload/`, {
method: 'POST',
body: formData,
headers: {}
});
const data: ThemesResponseType = await response.json();
return data;
}
}
};