search
This commit is contained in:
1 parent
bd32044427
commit
faa2e70e08
4 files changed
+73
-1
No files matched your search
@@ -106,6 +106,8 @@ export default function createApi(log: Log, pg: Pg, discogs) {
|
||||
|
||||
router.get('/bundles', async (ctx, next) => {
|
||||
const bundles = await getBundles();
|
||||
const search = await discogs.searchMaster('nine inch nails', 'the fragile');
|
||||
log.info(search);
|
||||
ctx.response.body = bundles;
|
||||
})
|
||||
|
||||
@@ -146,6 +148,12 @@ export default function createApi(log: Log, pg: Pg, discogs) {
|
||||
ctx.response.body = want;
|
||||
});
|
||||
|
||||
router.post('/want/search', async function wantPost(ctx, next) {
|
||||
const { artist, title } = ctx.request.body;
|
||||
const results = await discogs.search(artist, title);
|
||||
ctx.response.body = results;
|
||||
});
|
||||
|
||||
app.use(router.routes());
|
||||
|
||||
return {
|
||||
|
||||
+12
-1
@@ -11,7 +11,7 @@ import { logAxiosError } from './utils';
|
||||
import { Pg } from './pg';
|
||||
|
||||
export default function discogs(log: Log, pg: Pg) {
|
||||
const TOKEN = 'wRTXuYZGOPsIQgKRGKCAkUkidGtvpSfQgPWkYIpD';
|
||||
const TOKEN = 'Discogs token=wRTXuYZGOPsIQgKRGKCAkUkidGtvpSfQgPWkYIpD';
|
||||
const apiBase = 'https://api.discogs.com'
|
||||
const discogsBase = 'https://www.discogs.com'
|
||||
|
||||
@@ -62,6 +62,16 @@ export default function discogs(log: Log, pg: Pg) {
|
||||
return data;
|
||||
}
|
||||
|
||||
async function search(artist: string, title: string) {
|
||||
const url = new URL(`${apiBase}/database/search`);
|
||||
url.searchParams.append('artist', artist);
|
||||
url.searchParams.append('title', title);
|
||||
url.searchParams.append('type', 'release');
|
||||
url.searchParams.append('format', 'vinyl');
|
||||
const { data: { results } } = await api.get(url.href);
|
||||
return results;
|
||||
}
|
||||
|
||||
async function inventory(user: string) {
|
||||
const res = await api.get(`${apiBase}/users/${user}/inventory`);
|
||||
return res.data.listings;
|
||||
@@ -103,5 +113,6 @@ export default function discogs(log: Log, pg: Pg) {
|
||||
listings,
|
||||
listing,
|
||||
release,
|
||||
search,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user