migrate catalogs addon to esm structure

This commit is contained in:
TheBeastLT
2023-11-01 14:54:09 +02:00
parent 614c3f4643
commit 0fc5adda6b
10 changed files with 37 additions and 47 deletions

View File

@@ -1,11 +1,11 @@
const Bottleneck = require('bottleneck');
const moment = require('moment')
const { addonBuilder } = require('stremio-addon-sdk');
const { Providers } = require('../addon/lib/filter')
const { createManifest, genres } = require('./lib/manifest');
const { getMetas } = require('./lib/metadata');
const { cacheWrapCatalog, cacheWrapIds } = require('./lib/cache');
const repository = require('./lib/repository');
import Bottleneck from 'bottleneck';
import moment from 'moment';
import { addonBuilder } from 'stremio-addon-sdk';
import { Providers } from '../addon/lib/filter.js';
import { createManifest, genres } from './lib/manifest.js';
import { getMetas } from './lib/metadata.js';
import { cacheWrapCatalog, cacheWrapIds } from './lib/cache.js';
import * as repository from './lib/repository.js';
const CACHE_MAX_AGE = parseInt(process.env.CACHE_MAX_AGE) || 4 * 60 * 60; // 4 hours in seconds
const STALE_REVALIDATE_AGE = 4 * 60 * 60; // 4 hours
@@ -96,4 +96,4 @@ function createCacheKey(catalogId, providers, genre, offset) {
return [catalogId, providers.join(','), genre, dateKey, offset].filter(x => x !== undefined).join('|');
}
module.exports = builder.getInterface();
export default builder.getInterface();

View File

@@ -1,5 +1,5 @@
const express = require('express');
const serverless = require('./serverless');
import express from 'express';
import serverless from './serverless.js';
const app = express();

View File

@@ -1,5 +1,5 @@
const cacheManager = require('cache-manager');
const mangodbStore = require('cache-manager-mongodb');
import cacheManager from 'cache-manager';
import mangodbStore from 'cache-manager-mongodb';
const CATALOG_TTL = process.env.STREAM_TTL || 24 * 60 * 60; // 24 hours
@@ -37,13 +37,10 @@ function cacheWrap(cache, key, method, options) {
return cache.wrap(key, method, options);
}
function cacheWrapCatalog(key, method) {
export function cacheWrapCatalog(key, method) {
return cacheWrap(remoteCache, key, method, { ttl: CATALOG_TTL });
}
function cacheWrapIds(key, method) {
export function cacheWrapIds(key, method) {
return cacheWrap(remoteCache, `ids|${key}`, method, { ttl: CATALOG_TTL });
}
module.exports = { cacheWrapCatalog, cacheWrapIds };

View File

@@ -180,9 +180,9 @@ button:active {
box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.2);
}
`;
const { Providers } = require('../../addon/lib/filter');
import { Providers } from '../../addon/lib/filter.js';
function landingTemplate(manifest, config = {}) {
export default function landingTemplate(manifest, config = {}) {
const providers = config.providers || [];
const background = manifest.background || 'https://dl.strem.io/addon-background.jpg';
@@ -272,5 +272,3 @@ function landingTemplate(manifest, config = {}) {
</html>`
}
module.exports = landingTemplate;

View File

@@ -1,6 +1,6 @@
const { Type } = require('../../addon/lib/types');
import { Type } from '../../addon/lib/types.js';
const genres = [
export const genres = [
'Yesterday',
'This Week',
'Last Week',
@@ -9,7 +9,7 @@ const genres = [
'All Time'
]
function createManifest() {
export function createManifest() {
return {
id: 'com.stremio.torrentio.catalog.addon',
version: '1.0.2',
@@ -52,5 +52,3 @@ function createManifest() {
}
};
}
module.exports = { createManifest, genres };

View File

@@ -1,12 +1,12 @@
const axios = require('axios');
const { Type } = require('../../addon/lib/types');
import axios from 'axios';
import { Type } from '../../addon/lib/types.js';
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
const KITSU_URL = 'https://anime-kitsu.strem.fun';
const TIMEOUT = 30000;
const MAX_SIZE = 40;
function getMetas(ids, type) {
export async function getMetas(ids, type) {
if (!ids.length || !type) {
return [];
}
@@ -39,5 +39,3 @@ function _sanitizeMeta(meta) {
delete meta.credits_crew;
return meta;
}
module.exports = { getMetas };

View File

@@ -1,11 +1,11 @@
const { Sequelize, QueryTypes } = require('sequelize');
const { Type } = require('../../addon/lib/types');
import { Sequelize, QueryTypes } from 'sequelize';
import { Type } from '../../addon/lib/types.js';
const DATABASE_URI = process.env.DATABASE_URI;
const database = new Sequelize(DATABASE_URI, { logging: false });
async function getIds(providers, type, startDate, endDate) {
export async function getIds(providers, type, startDate, endDate) {
const idName = type === Type.ANIME ? 'kitsuId' : 'imdbId';
const episodeCondition = type === Type.SERIES
? 'AND files."imdbSeason" IS NOT NULL AND files."imdbEpisode" IS NOT NULL'
@@ -32,5 +32,3 @@ async function getIds(providers, type, startDate, endDate) {
const results = await database.query(query, { type: QueryTypes.SELECT });
return results.map(result => `${result.imdbId || result.kitsuId}`);
}
module.exports = { getIds };

View File

@@ -1,12 +1,12 @@
{
"name": "stremio-torrentio-catalogs",
"version": "1.0.2",
"version": "1.0.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "stremio-torrentio-catalogs",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"dependencies": {
"axios": "^0.27.2",

View File

@@ -1,7 +1,8 @@
{
"name": "stremio-torrentio-catalogs",
"version": "1.0.2",
"main": "index.js",
"version": "1.0.3",
"exports": "./index.js",
"type": "module",
"scripts": {
"start": "node index.js"
},

View File

@@ -1,8 +1,8 @@
const { getRouter } = require('stremio-addon-sdk');
const addonInterface = require('./addon');
const qs = require('querystring')
const { parseConfiguration } = require('../addon/lib/configuration');
const { createManifest } = require('./lib/manifest');
import getRouter from 'stremio-addon-sdk/src/getRouter.js';
import addonInterface from './addon.js';
import qs from 'querystring';
import { parseConfiguration } from '../addon/lib/configuration.js';
import { createManifest } from './lib/manifest.js';
const router = getRouter(addonInterface);
@@ -60,7 +60,7 @@ router.get('/:configuration/:resource/:type/:id/:extra?.json', (req, res, next)
});
});
module.exports = function (req, res) {
export default function (req, res) {
router(req, res, function () {
res.statusCode = 404;
res.end();