Server emulator thing
This commit is contained in:
parent
9a77aae56b
commit
6db34b9cee
|
@ -0,0 +1,82 @@
|
||||||
|
const dummyTags = ['dark', 'light', 'simple', 'minimal', 'extra', 'something', 'tag', 'whatever', 'another', 'transparent'];
|
||||||
|
|
||||||
|
export default class ServerEmu {
|
||||||
|
|
||||||
|
static async themes(args) {
|
||||||
|
if (!this._themes) this._themes = this.generateThemes();
|
||||||
|
|
||||||
|
await new Promise(r => setTimeout(r, Math.random() * 3000));
|
||||||
|
|
||||||
|
return {
|
||||||
|
docs: this._themes,
|
||||||
|
pagination: {
|
||||||
|
total: this._themes.length,
|
||||||
|
pages: this._themes.length / 9,
|
||||||
|
limit: 0,
|
||||||
|
page: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static generateThemes() {
|
||||||
|
const docs = [];
|
||||||
|
const count = Math.floor(Math.random() * 50 + 30);
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const id = `theme${i}-${this.randomId()}`;
|
||||||
|
const name = `Dummy Theme ${i}`;
|
||||||
|
const tags = dummyTags.sort(() => .5 - Math.random()).slice(0, 3);
|
||||||
|
|
||||||
|
docs.push({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
tags,
|
||||||
|
installs: Math.floor(Math.random() * 5000) + 5000,
|
||||||
|
updated: this.randomTimestamp(),
|
||||||
|
rating: Math.floor(Math.random() * 500) + 500,
|
||||||
|
activeUsers: Math.floor(Math.random() * 1000) + 1000,
|
||||||
|
rated: Math.random() > .5,
|
||||||
|
version: this.randomVersion(),
|
||||||
|
repository: this.dummyRepo,
|
||||||
|
files: this.dummyFiles,
|
||||||
|
author: this.dummyAuthor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get dummyRepo() {
|
||||||
|
return {
|
||||||
|
name: 'ExampleRepository',
|
||||||
|
baseUri: 'https://github.com/Jiiks/ExampleRepository',
|
||||||
|
rawUri: 'https://github.com/Jiiks/ExampleRepository/raw/master'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static get dummyFiles() {
|
||||||
|
return {
|
||||||
|
readme: 'Example/readme.md',
|
||||||
|
previews: [{
|
||||||
|
large: 'Example/preview1-big.png',
|
||||||
|
thumb: 'Example/preview1-small.png'
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static get dummyAuthor() {
|
||||||
|
return 'Someone';
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomId() {
|
||||||
|
return btoa(Math.random()).substring(3, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomTimestamp() {
|
||||||
|
return `2018-${Math.floor((Math.random() * 12) + 1).toString().padStart(2, '0')}-${Math.floor((Math.random() * 30) + 1).toString().padStart(2, '0')}T14:51:32.057Z`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomVersion() {
|
||||||
|
return `${Math.round(Math.random() * 3)}.${Math.round(Math.random() * 10)}.${Math.round(Math.random() * 10)}`;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,8 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import ServerEmu from '../dev/serveremu';
|
||||||
|
|
||||||
import { request } from 'vendor';
|
import { request } from 'vendor';
|
||||||
|
|
||||||
const APIBASE = 'ifyouareinwebtestthenyouknowwhatthisshouldbe'; // Do not push
|
const APIBASE = 'ifyouareinwebtestthenyouknowwhatthisshouldbe'; // Do not push
|
||||||
|
@ -19,54 +21,6 @@ const ENDPOINTS = {
|
||||||
'statistics': `${APIBASE}/statistics`
|
'statistics': `${APIBASE}/statistics`
|
||||||
};
|
};
|
||||||
|
|
||||||
const dummyTags = ['tag1', 'tag2', 'tag3', 'tag4', 'tag5'];
|
|
||||||
const dummyRepo = {
|
|
||||||
name: 'ExampleRepository',
|
|
||||||
baseUri: 'https://github.com/Jiiks/ExampleRepository',
|
|
||||||
rawUri: 'https://github.com/Jiiks/ExampleRepository/raw/master'
|
|
||||||
};
|
|
||||||
const dummyVersion = () => `${Math.round(Math.random() * 3)}.${Math.round(Math.random() * 10)}.${Math.round(Math.random() * 10)}`;
|
|
||||||
const dummyFiles = {
|
|
||||||
readme: 'Example/readme.md',
|
|
||||||
previews: [{
|
|
||||||
large: 'Example/preview1-big.png',
|
|
||||||
thumb: 'Example/preview1-small.png'
|
|
||||||
}]
|
|
||||||
};
|
|
||||||
const dummyAuthor = 'DummyAuthor';
|
|
||||||
const dummyTimestamp = () => `2018-${Math.floor((Math.random() * 12) + 1).toString().padStart(2, '0')}-${Math.floor((Math.random() * 30) + 1).toString().padStart(2, '0')}T14:51:32.057Z`;
|
|
||||||
|
|
||||||
async function dummyThemes() {
|
|
||||||
// Simulate get
|
|
||||||
await new Promise(r => setTimeout(r, Math.random() * 3000));
|
|
||||||
const dummies = [];
|
|
||||||
for (let i = 0; i < 10; i++) {
|
|
||||||
dummies.push({
|
|
||||||
id: `theme${i}${btoa(Math.random()).substring(3, 9)}`,
|
|
||||||
name: `Dummy ${i}`,
|
|
||||||
tags: dummyTags,
|
|
||||||
installs: Math.floor(Math.random() * 10000),
|
|
||||||
updated: dummyTimestamp(),
|
|
||||||
rating: Math.floor(Math.random() * 1000),
|
|
||||||
activeUsers: Math.floor(Math.random() * 1000),
|
|
||||||
rated: Math.random() > .5,
|
|
||||||
version: dummyVersion(),
|
|
||||||
repository: dummyRepo,
|
|
||||||
files: dummyFiles,
|
|
||||||
author: dummyAuthor
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
docs: dummies,
|
|
||||||
pagination: {
|
|
||||||
total: 25,
|
|
||||||
pages: 3,
|
|
||||||
limit: 9,
|
|
||||||
page: 1
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class BdWebApi {
|
export default class BdWebApi {
|
||||||
|
|
||||||
static get themes() {
|
static get themes() {
|
||||||
|
@ -89,7 +43,8 @@ export default class BdWebApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
static getThemes(args) {
|
static getThemes(args) {
|
||||||
return dummyThemes();
|
return ServerEmu.themes(args);
|
||||||
|
// return dummyThemes();
|
||||||
/*
|
/*
|
||||||
if (!args) return request.get(ENDPOINTS.themes);
|
if (!args) return request.get(ENDPOINTS.themes);
|
||||||
const { id } = args;
|
const { id } = args;
|
||||||
|
|
Loading…
Reference in New Issue