Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function Api({
baseUrl,
timeout = DEFAULT_TIMEOUT
}: {
baseUrl: string,
timeout?: number
}) {
let status: ServerStatus = STATUS.STARTING;
let timeoutId: TimeoutID;
// We append this to requests for presets and map styles, in order to override
// the local static server cache whenever the app is restarted. NB. sprite,
// font, and map tile requests might still be cached, only changes in the map
// style will be cache-busted.
const startupTime = Date.now();
const req = ky.extend({
prefixUrl: baseUrl,
// No timeout because indexing after first sync takes a long time, which mean
// requests to the server take a long time
timeout: false,
headers: {
"cache-control": "no-cache",
pragma: "no-cache"
}
});
const pending: Array<{ resolve: () => any, reject: Error => any }> = [];
let listeners: Array<(status: ServerStatus) => any> = [];
nodejs.channel.addListener("status", onStatusChange);
function onStatusChange(newStatus: ServerStatus) {
import Ky from 'ky'
import useEndpoint from '@/composables/use-endpoint'
const BASE_URL = 'https://jsonplaceholder.typicode.com'
const ky = Ky.extend({
prefixUrl: BASE_URL,
})
const POSTS_URL = 'posts'
const IMAGES_URL = 'photos'
function getPosts({ start = 0, limit = 5 } = {}) {
return wait(
ky(POSTS_URL, {
searchParams: {
_start: start,
_limit: limit,
},
}).json()
)
}
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'
import { getAppRoot } from '../lib/common'
const api = ky.extend({ prefixUrl: getAppRoot() + '/api/' })
export default class ReportContainer extends Container {
constructor (props) {
super(props)
this.state = {
total: 0,
reports: [],
currentReport: {},
isFetching: false
}
}
async fetchReports (order = 'desc', sort = 'date', page = 0, projectId = 0) {
this.setState({
isFetching: true
})
import { Container } from 'unstated'
import ky from 'ky'
import _ from 'lodash'
import { toaster } from 'evergreen-ui'
import { getAppRoot } from '../lib/common'
const api = ky.extend({ prefixUrl: getAppRoot() + '/api/' })
export default class ProjectContainer extends Container {
constructor (props) {
super(props)
this.state = {
totalProjects: 0,
projects: [],
isFetching: false,
currentProject: {}
}
}
async fetchProjects (order = 'desc', page = 0) {
this.setState({
isFetching: true
})
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'
import { getAppRoot } from '../lib/common'
const api = ky.extend({ prefixUrl: getAppRoot() + '/api/reports/' })
export default class OptionsContainer extends Container {
constructor (props) {
super(props)
this.state = {
options: 0,
isFetching: false
}
}
async fetchOptions (reportId) {
this.setState({
isFetching: true
})
try {
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'
import { getAppRoot } from '../lib/common'
const api = ky.extend({ prefixUrl: getAppRoot() + '/api/reports/' })
export default class CompareContainer extends Container {
constructor (props) {
super(props)
this.state = {
report1: null,
report2: null,
isFetching: false
}
}
async fetchReports (reportId1, reportId2) {
this.setState({
isFetching: true
})
function client(base, options = {}) {
return ky.extend({
prefixUrl: base,
credentials,
headers,
timeout,
...options,
});
}
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'
import { getAppRoot } from '../lib/common'
const api = ky.extend({ prefixUrl: getAppRoot() + '/api/' })
export default class InfoContainer extends Container {
constructor (props) {
super(props)
this.state = {
info: null,
isFetching: false
}
}
async fetchInfo () {
this.setState({
isFetching: true
})
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'
import { getAppRoot } from '../lib/common'
const api = ky.extend({ prefixUrl: getAppRoot() + '/api/reports/' })
export default class HistogramContainer extends Container {
constructor (props) {
super(props)
this.state = {
histogram: 0,
isFetching: false
}
}
async fetchHistogram (reportId) {
this.setState({
isFetching: true
})
try {