f0ck-fe-old/test4/js/api.js

43 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2021-12-31 06:18:41 +00:00
import rt from './runtimes.js';
import { render } from './helper.js';
export const api = {
items: new Map(),
meta: [],
getItems: function() {
return fetch("//api.allorigins.win/raw?url=https://f0ck.me/api/p", {
headers: {
//'Accept': 'application/json',
//'Content-Type': 'application/json'
},
method: 'GET'
//method: 'POST',
//body: JSON.stringify({ ...rt.events.hash, eps: rt.events.dims.eps })
})
.then(res => res.status === 200? res.json() : {error:true} )
.then(data => {
if(!data.error) {
this.meta = data.meta;
[...data.items.prev, ...data.items.next].forEach(e => this.items.set(e.stamp, e));
}
return {
prev: data.items.prev.sort().reverse(),
next: data.items.next.sort().reverse()
};
})
.then(data => {
this.items = new Map([...this.items.entries()].sort().reverse());
console.log(data);
});
},
get pos() {
return {
latest: [...this.items][0],
first: [...this.items][this.items.size - 1]
};
}
};
api.getItems().then(() => {
render(api.items);
});