Skip to content

Commit

Permalink
feat: aliyun esa purge
Browse files Browse the repository at this point in the history
  • Loading branch information
eallion committed Oct 29, 2024
1 parent 5976658 commit 3977521
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ jobs:
./ve configure set --profile volcengine-hugo-github-actions --region cn-beijing --endpoint cdn.volcengineapi.com --access-key ${{ secrets.VOLC_ACCESS_KEY }} --secret-key ${{ secrets.VOLC_SECRET_KEY }}
./ve cdn SubmitRefreshTask --body '{"Type":"dir","Urls":"https://www.eallion.com/"}' > /dev/null 2>&1 || true
- name: Refresh Aliyun ESA
run: node scripts/aliyun-esa-purge.js
env:
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }}
ESA_SITE_ID: ${{ secrets.ESA_SITE_ID }}
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"scripts": {
"dev": "cd themes/blowfish && npm install && cd ../.. && set NODE_ENV=development && node ./themes/blowfish/node_modules/tailwindcss/lib/cli.js -c ./themes/blowfish/tailwind.config.js -i ./themes/blowfish/assets/css/main.css -o ./assets/css/compiled/main.css --jit -w",
"build": "cd themes/blowfish && npm install && cd ../.. && set NODE_ENV=production&&node ./themes/blowfish/node_modules/tailwindcss/lib/cli.js -c ./themes/blowfish/tailwind.config.js -i ./themes/blowfish/assets/css/main.css -o ./assets/css/compiled/main.css --jit",
"esa": "node scripts/esa-purge.js",
"hns": "net stop hns && net start hns",
"hugo": "hugo --minify --enableGitInfo",
"new": "node scripts/new_post.js",
"prepare": "husky",
Expand All @@ -15,8 +17,7 @@
"shiki": "npx rehype-cli public -o",
"theme": "git submodule update --remote --merge",
"vercel": "node scripts/vercel_env_hugo_version.js && hugo --minify --enableGitInfo && next build",
"winnat": "net stop winnat -y && net start winnat -y",
"hns": "net stop hns && net start hns"
"winnat": "net stop winnat -y && net start winnat -y"
},
"repository": {
"type": "git",
Expand All @@ -34,14 +35,25 @@
"url": "https://github.com/eallion/eallion.com/issues"
},
"homepage": "https://github.com/eallion/eallion.com#readme",
"devDependencies": {
"@types/node": "^20.17.2",
"nyc": "^15.1.0",
"source-map-support": "^0.5.21",
"ts-node": "^8.10.2",
"typescript": "^3.9.10"
},
"dependencies": {
"@shikijs/rehype": "^1.16.1",
"@types/node": "^20.16.3",
"@alicloud/esa20240910": "2.5.0",
"@alicloud/openapi-client": "^0.4.12",
"@alicloud/tea-console": "^1.0.0",
"@alicloud/tea-typescript": "^1.8.0",
"@alicloud/tea-util": "^1.4.9",
"@shikijs/rehype": "^1.22.2",
"axios": "^1.7.7",
"dotenv": "^16.4.5",
"fs": "0.0.1-security",
"husky": "^9.1.5",
"rehype-cli": "^12.0.0",
"shiki": "^1.16.1"
"husky": "^9.1.6",
"rehype-cli": "^12.0.1",
"shiki": "^1.22.2"
}
}
62 changes: 62 additions & 0 deletions scripts/aliyun-esa-purge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';
// This file is auto-generated, don't edit it
// 依赖的模块可通过下载工程中的模块依赖文件或右上角的获取 SDK 依赖信息查看
const ESA20240910 = require('@alicloud/esa20240910');
const OpenApi = require('@alicloud/openapi-client');
const Console = require('@alicloud/tea-console');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');

class Client {

/**
* 使用 AK&SK 初始化账号 Client
* @return Client
* @throws Exception
*/
static createClient() {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378664.html。
let config = new OpenApi.Config({
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
accessKeyId: process.env['ACCESS_KEY_ID'],
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
accessKeySecret: process.env['ACCESS_KEY_SECRET'],
});
// Endpoint 请参考 https://api.aliyun.com/product/ESA
config.endpoint = `esa.cn-hangzhou.aliyuncs.com`;
return new ESA20240910.default(config);
}

static async main(args) {
let client = Client.createClient();
let content = new ESA20240910.PurgeCachesRequestContent({
// Array, 可选,目录刷新列表,类型为 directory 时需要指定。 > 每次最多 100 条,每次最多包含 10 个不同域名。
directories: [
'https://www.eallion.com/'
],
});
let purgeCachesRequest = new ESA20240910.PurgeCachesRequest({
type: 'directory',
siteId: process.env['ESA_SITE_ID'],
// Object, 可选
content: content,
});
let runtime = new Util.RuntimeOptions({ });
try {
let resp = await client.purgeCachesWithOptions(purgeCachesRequest, runtime);
Console.default.log(Util.default.toJSONString(resp));
} catch (error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
console.log(error.message);
// 诊断地址
console.log(error.data["Recommend"]);
Util.default.assertAsString(error.message);
}
}

}

exports.Client = Client;
Client.main(process.argv.slice(2));

0 comments on commit 3977521

Please sign in to comment.