diff --git a/catalogs/addon.js b/catalogs/addon.js index 5eea583..a07e60e 100644 --- a/catalogs/addon.js +++ b/catalogs/addon.js @@ -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(); diff --git a/catalogs/index.js b/catalogs/index.js index c072f1e..3d55fa9 100644 --- a/catalogs/index.js +++ b/catalogs/index.js @@ -1,5 +1,5 @@ -const express = require('express'); -const serverless = require('./serverless'); +import express from 'express'; +import serverless from './serverless.js'; const app = express(); diff --git a/catalogs/lib/cache.js b/catalogs/lib/cache.js index c9e4c90..57b8c3b 100644 --- a/catalogs/lib/cache.js +++ b/catalogs/lib/cache.js @@ -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 }; - diff --git a/catalogs/lib/landingTemplate.js b/catalogs/lib/landingTemplate.js index b1c55d7..68f6090 100644 --- a/catalogs/lib/landingTemplate.js +++ b/catalogs/lib/landingTemplate.js @@ -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 = {}) { ` } - -module.exports = landingTemplate; \ No newline at end of file diff --git a/catalogs/lib/manifest.js b/catalogs/lib/manifest.js index fc01273..37cbb99 100644 --- a/catalogs/lib/manifest.js +++ b/catalogs/lib/manifest.js @@ -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 }; \ No newline at end of file diff --git a/catalogs/lib/metadata.js b/catalogs/lib/metadata.js index b42e32c..47a6f6e 100644 --- a/catalogs/lib/metadata.js +++ b/catalogs/lib/metadata.js @@ -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 }; diff --git a/catalogs/lib/repository.js b/catalogs/lib/repository.js index 74a58c7..c32dd9e 100644 --- a/catalogs/lib/repository.js +++ b/catalogs/lib/repository.js @@ -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 }; \ No newline at end of file diff --git a/catalogs/package-lock.json b/catalogs/package-lock.json index 3435c0f..baa7cdc 100644 --- a/catalogs/package-lock.json +++ b/catalogs/package-lock.json @@ -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", diff --git a/catalogs/package.json b/catalogs/package.json index 6deded9..8122239 100644 --- a/catalogs/package.json +++ b/catalogs/package.json @@ -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" }, diff --git a/catalogs/serverless.js b/catalogs/serverless.js index c673284..ec028bb 100644 --- a/catalogs/serverless.js +++ b/catalogs/serverless.js @@ -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();