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,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 };