68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
const knex = require('./knex');
|
|
|
|
async function curateRelease(release) {
|
|
const actors = await knex('actors_associated')
|
|
.select('actors.id', 'actors.name', 'actors.gender')
|
|
.where({ release_id: release.id })
|
|
.leftJoin('actors', 'actors.id', 'actors_associated.actor_id');
|
|
|
|
const tags = await knex('tags_associated')
|
|
.select('tags.tag', 'tags.capitalization')
|
|
.where({ release_id: release.id })
|
|
.leftJoin('tags', 'tags.tag', 'tags_associated.tag_id');
|
|
|
|
return {
|
|
id: release.id,
|
|
title: release.title,
|
|
date: release.date,
|
|
description: release.description,
|
|
url: release.url,
|
|
shootId: release.shoot_id,
|
|
entryId: release.entry_id,
|
|
actors,
|
|
director: release.director,
|
|
tags,
|
|
rating: {
|
|
likes: release.likes,
|
|
dislikes: release.dislikes,
|
|
stars: release.stars,
|
|
},
|
|
site: {
|
|
id: release.site_id,
|
|
name: release.site_name,
|
|
url: release.site_url,
|
|
},
|
|
network: {
|
|
id: release.network_id,
|
|
name: release.network_name,
|
|
url: release.network_url,
|
|
},
|
|
};
|
|
}
|
|
|
|
function curateReleases(releases) {
|
|
return Promise.all(releases.map(async release => curateRelease(release)));
|
|
}
|
|
|
|
async function fetchReleases(releaseId) {
|
|
// const thumbnails = await fs.readdir(path.join(config.thumbnailPath, release.site.id.toString(), release.id.toString()));
|
|
|
|
const releases = await knex('releases')
|
|
.where(releaseId ? { 'releases.id': releaseId } : {})
|
|
.select('releases.*', 'sites.name as site_name', 'sites.url as site_url', 'sites.network_id', 'networks.name as network_name', 'networks.url as network_url')
|
|
.leftJoin('sites', 'releases.site_id', 'sites.id')
|
|
.leftJoin('networks', 'sites.network_id', 'networks.id')
|
|
.orderBy('date', 'desc')
|
|
.limit(100);
|
|
|
|
// console.log(curateReleases(releases));
|
|
|
|
return curateReleases(releases);
|
|
}
|
|
|
|
module.exports = {
|
|
fetchReleases,
|
|
};
|