2022-03-08 14:32:01 +03:00
|
|
|
import {Response} from 'miragejs';
|
2016-08-23 17:27:46 +03:00
|
|
|
|
2016-08-17 18:01:46 +03:00
|
|
|
let themeCount = 1;
|
|
|
|
|
|
|
|
export default function mockThemes(server) {
|
2017-02-21 21:28:44 +03:00
|
|
|
server.get('/themes');
|
|
|
|
|
2024-03-27 20:37:37 +03:00
|
|
|
server.get('/themes/active/', function ({themes}) {
|
|
|
|
const theme = themes.findBy({active: true});
|
|
|
|
|
|
|
|
return {themes: [theme]};
|
|
|
|
});
|
|
|
|
|
2017-02-21 21:28:44 +03:00
|
|
|
server.post('/themes/upload/', function ({themes}) {
|
2016-08-17 18:01:46 +03:00
|
|
|
// pretender/mirage doesn't currently process FormData so we can't use
|
|
|
|
// any info passed in through the request
|
|
|
|
let theme = {
|
|
|
|
name: `test-${themeCount}`,
|
|
|
|
package: {
|
|
|
|
name: `Test ${themeCount}`,
|
|
|
|
version: '0.1'
|
2017-02-21 21:28:44 +03:00
|
|
|
}
|
2016-08-17 18:01:46 +03:00
|
|
|
};
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
themeCount += 1;
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2017-02-21 21:28:44 +03:00
|
|
|
theme = themes.create(theme);
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2017-03-14 16:54:58 +03:00
|
|
|
return {themes: [theme]};
|
2016-08-17 18:01:46 +03:00
|
|
|
});
|
2016-08-23 17:27:46 +03:00
|
|
|
|
2017-02-21 21:28:44 +03:00
|
|
|
server.del('/themes/:theme/', function ({themes}, {params}) {
|
|
|
|
themes.findBy({name: params.theme}).destroy();
|
2016-08-23 17:27:46 +03:00
|
|
|
|
2019-04-05 19:27:14 +03:00
|
|
|
return new Response(204);
|
2016-08-23 17:27:46 +03:00
|
|
|
});
|
2017-03-03 18:31:42 +03:00
|
|
|
|
|
|
|
server.put('/themes/:theme/activate/', function ({themes}, {params}) {
|
|
|
|
themes.all().update('active', false);
|
2017-03-14 16:54:58 +03:00
|
|
|
let theme = themes.findBy({name: params.theme}).update({active: true});
|
2017-03-03 18:31:42 +03:00
|
|
|
|
2017-03-14 16:54:58 +03:00
|
|
|
return {themes: [theme]};
|
2017-03-03 18:31:42 +03:00
|
|
|
});
|
2021-11-01 20:48:49 +03:00
|
|
|
|
2021-11-01 21:40:47 +03:00
|
|
|
server.post('/themes/install/', function ({themes}, {queryParams}) {
|
2021-11-01 20:48:49 +03:00
|
|
|
themes.all().update('active', false);
|
|
|
|
|
|
|
|
const themeName = queryParams.ref.replace('TryGhost/', '');
|
|
|
|
|
|
|
|
let theme = themes.findBy({name: themeName});
|
|
|
|
if (theme) {
|
|
|
|
theme.update({active: true});
|
|
|
|
} else {
|
|
|
|
theme = themes.create({
|
|
|
|
name: themeName,
|
|
|
|
package: {
|
|
|
|
name: themeName,
|
|
|
|
version: '0.1'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {themes: [theme]};
|
|
|
|
});
|
2016-08-17 18:01:46 +03:00
|
|
|
}
|