env files, fixes for discogs sync
This commit is contained in:
1 parent
1ee8dbc749
commit
1ca9a7225c
6 files changed
+31
-14
No files matched your search
@@ -48,12 +48,4 @@ describe('api', function apiTests() {
|
||||
assert(res.headers['set-cookie']);
|
||||
})
|
||||
});
|
||||
|
||||
describe('offers', function offerTests() {
|
||||
it('create offers', async function createOffersTest() {
|
||||
const { data: bundles } = await api.get('/bundles');
|
||||
const listingIds = bundles[0].items.map(i => i.id);
|
||||
const { data } = await api.post('/offers', { listingIds, shipping: 50.0, baseShipping: 15.0 });
|
||||
});
|
||||
});
|
||||
});
|
||||
+6
-1
@@ -29,6 +29,10 @@ export default function createApi(log: Log, pg: Pg, discogs: Discogs, offers: Of
|
||||
|
||||
const app = koaWebsocket(new koa());
|
||||
|
||||
BigInt.prototype.toJSON = function bigIntStringify() {
|
||||
return this.toString();
|
||||
};
|
||||
|
||||
app.use(async (ctx, next) => {
|
||||
try {
|
||||
await next();
|
||||
@@ -46,6 +50,7 @@ export default function createApi(log: Log, pg: Pg, discogs: Discogs, offers: Of
|
||||
function listen() {
|
||||
const server = app.listen(PORT);
|
||||
log.info({ PORT }, 'listening');
|
||||
return server;
|
||||
}
|
||||
|
||||
app.use(cors({ credentials: true }));
|
||||
@@ -68,7 +73,7 @@ export default function createApi(log: Log, pg: Pg, discogs: Discogs, offers: Of
|
||||
const { username } = ctx.request.body;
|
||||
const user = await pg.userFindId(ctx.state.user.id);
|
||||
const wants = await discogs.wantListSync(username, user);
|
||||
events.emit(Events.WantsAdded, [wants]);
|
||||
events.emit(Events.WantsAdded, wants);
|
||||
ctx.response.body = wants;
|
||||
});
|
||||
|
||||
|
||||
@@ -27,6 +27,21 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
},
|
||||
});
|
||||
|
||||
function onSuccess(response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
function onError(error) {
|
||||
// if (error.response) return [error.response.data.error, null];
|
||||
// if (error.request) return ['Network Error', null];
|
||||
// return ['Unknown Error', null];
|
||||
if (error.response.status === 429) {
|
||||
throw new Error('rate limited, try again in 1 minute');
|
||||
}
|
||||
}
|
||||
|
||||
api.interceptors.response.use(onSuccess, onError);
|
||||
|
||||
async function handleApiError(e) {
|
||||
logAxiosError(e);
|
||||
if (e.response.status === 429) {
|
||||
@@ -45,6 +60,7 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
|
||||
// convert want object to actual release and ignore duplicate errors
|
||||
const results = await Promise.allSettled(releases.map(release => pg.wantCreate(release, user)));
|
||||
log.info(results);
|
||||
// @ts-ignore
|
||||
const additions = results.filter(r => r.status === 'fulfilled').map(r => r.value);
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ export function logAxiosError(e) {
|
||||
export function wantDetails(want: Want) {
|
||||
const data = want.data as any;
|
||||
|
||||
if (!data) console.warn(want);
|
||||
|
||||
return {
|
||||
title: data.title,
|
||||
release: data.id,
|
||||
|
||||
Reference in new issue
Block a user