Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
update jsdelivr
Browse files Browse the repository at this point in the history
  • Loading branch information
k03mad committed Jan 25, 2024
1 parent 9004f9a commit 9f68f02
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Lampa Plugins

— Дополнительное меню выбора плагинов из этого репозитория \
https://raw.githack.com/k03mad/lampa/master/plugins/add-store.js \
https://cdn.jsdelivr.net/gh/k03mad/lampa/plugins/add-store.js

— Добавить Мультфильмы и расположить вместе с Аниме после Сериалов \
https://raw.githack.com/k03mad/lampa/master/plugins/add-mult.js \
https://cdn.jsdelivr.net/gh/k03mad/lampa/plugins/add-mult.js

— Скрыть иконки Премиума и Ленты из верхнего тулбара \
https://raw.githack.com/k03mad/lampa/master/plugins/hide-icons.js \
https://cdn.jsdelivr.net/gh/k03mad/lampa/plugins/hide-icons.js
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@k03mad/request": "5.6.0",
"@k03mad/simple-log": "2.1.0",
"globby": "14.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/add-store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const NEW_ITEM_ATTR = 'data-component="mad_store"';
const NEW_ITEM_SELECTOR = `[${NEW_ITEM_ATTR}]`;
const NEW_ITEM_TEXT = 'Расширения :: Mad';
const NEW_ITEM_LINK = 'https://raw.githack.com/k03mad/lampa/master/plugins/store.json';
const NEW_ITEM_LINK = 'https://cdn.jsdelivr.net/gh/k03mad/lampa/plugins/store.json';

const ITEM_PLUGINS_SELECTOR = '[data-component="plugins"]';

Expand Down
8 changes: 4 additions & 4 deletions plugins/store.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
{
"name": "Добавить Мультфильмы и расположить вместе с Аниме после Сериалов",
"author": "https://github.com/k03mad/lampa",
"link": "https://raw.githack.com/k03mad/lampa/master/plugins/add-mult.js",
"link": "https://cdn.jsdelivr.net/gh/k03mad/lampa/plugins/add-mult.js",
"available_lampa": 1
},
{
"name": "Скрыть иконки Премиума и Ленты из верхнего тулбара",
"author": "https://github.com/k03mad/lampa",
"link": "https://raw.githack.com/k03mad/lampa/master/plugins/hide-icons.js",
"link": "https://cdn.jsdelivr.net/gh/k03mad/lampa/plugins/hide-icons.js",
"available_lampa": 1
}
]
Expand All @@ -24,13 +24,13 @@
{
"name": "Альтернативный магазин плагинов",
"author": "https://github.com/lampaplugins/store",
"link": "https://raw.githack.com/lampaplugins/store/main/store.js",
"link": "https://cdn.jsdelivr.net/gh/lampaplugins/store/store.js",
"available_lampa": 1
},
{
"name": "Источник КиноПоиск",
"author": "https://github.com/nb557/plugins",
"link": "https://raw.githack.com/nb557/plugins/main/kp_source.js",
"link": "https://cdn.jsdelivr.net/gh/nb557/plugins/kp_source.js",
"available_lampa": 1
}
]
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 37 additions & 5 deletions scripts/cache-purge.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
import fs from 'node:fs/promises';

import {request} from '@k03mad/request';
import {logErrorExit} from '@k03mad/simple-log';
import {globby} from 'globby';

const PUBLIC_DIR = './public';
const PLUGINS_DIR = './plugins';
const STORE_CONFIG = `${PLUGINS_DIR}/store.json`;

const PURGE_URL = 'https://purge.jsdelivr.net/gh/k03mad/lampa/';
const CDN_DOMAIN = 'https://cdn.jsdelivr.net';
const PURGE_DOMAIN = 'https://purge.jsdelivr.net';
const PURGE_PATH = '/gh/k03mad/lampa/';
const PURGE_RPS = 1;

const purgeRequest = file => request(PURGE_URL + file, {}, {rps: PURGE_RPS});
const [
myPluginsFiles,
storeConfig,
] = await Promise.all([
globby(PLUGINS_DIR),
fs.readFile(STORE_CONFIG, {encoding: 'utf8'}),
]);

const myCdnUrls = myPluginsFiles
.map(link => PURGE_DOMAIN + PURGE_PATH + link);

if (myCdnUrls.length === 0) {
logErrorExit(`Plugins CDN urls not found: ${PLUGINS_DIR}`);
}

const storeCdnUrls = JSON
.parse(storeConfig)
.results
.flatMap(({results}) => results.map(({link}) => link.replace(CDN_DOMAIN, PURGE_DOMAIN)))
.filter(link => link.includes(PURGE_DOMAIN));

if (storeCdnUrls.length === 0) {
logErrorExit(`Store CDN urls not found: ${PLUGINS_DIR}`);
}

const urls = new Set([myCdnUrls, storeCdnUrls].flat());

const files = await globby(PUBLIC_DIR);
await Promise.all(files.map(purgeRequest));
await Promise.all([...urls].map(
url => request(url, {}, {rps: PURGE_RPS}),
));

0 comments on commit 9f68f02

Please sign in to comment.