阿里云函数 FC 文档
提示
在没有资源包的情况下,每月可能需要 1 元左右的费用。(不启用阿里云日志,除风纪任务外,未开启其他如天选,直播心跳等耗时任务)
阿里云函数可在配置里将 vCPU 设置为 0.1 核,内存设置为 128M,这样费用会更低。
创建一个服务,日志可有可无,过程略
然后在服务下创建一个函数
基础配置
- 运行环境选择最新的
Nodejs
(最低请选择 14)
触发器配置
安装或更新
云函数使用了镜像加速,但是镜像不是实时更新的,如果想要今天刚更新的模块,请设置源为默认。
bash
npm config set registry https://registry.npmjs.org/
然后执行(安装/更新依赖,都是同样的)
bash
npm install bilioutils
可能因为 node 版本出现类似的错误
bash
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
error responselike@3.0.0: The engine "node" is incompatible with this module. Expected version ">=14.16". Got "12.14.1"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
可以运行如下命令,忽略错误后安装/更新(因为安装和运行环境的版本不一样,所以不用担心)
bash
npm config set ignore-engines true
npm install bilioutils
修改 index.js 的代码
javascript
exports.handler = require('bilioutils').fc_handler();
最后参考图中位置,添加配置文件,再点击部署
更新 Cookie
可能需要安装一个依赖
bash
npm install @catlair/blogin
然后执行如下命令
bash
npx bilioutils -l
再使用手机扫码,如果 mid 存在于配置文件中,会自动更新,否则获取到的 cookie 会打印到控制台,以及 log 文件,请自行复制到配置文件中。
随机时间运行(可选)
获取 ARM ID 和 KEY
创建用户
添加 FC 的权限,并在此复制 ID 和 KEY
将 ALI_SECRET_ID
和 ALI_SECRET_KEY
添加到云函数的配置中(位置参考)
视频参考
配置文件
以下 config.json
或 config.json5
都是符合要求的配置文件位置,选则一个合适的位置即可。如果你创建了多个,那。。。。别创建多个啊。
bash
├── config
│ ├── config.json
│ └── config.json5
└── src
├── config
│ ├── config.json
│ └── config.json5
├── config.json
├── config.json5
└── index.js
或者这样更加生动
config
src
自定义任务
讨论:https://github.com/catlair/BiliOutils/issues/90#issuecomment-1190976142
将触发器附加内容设置为:
json5
{ task: 'xxxx,yyyy,zzzz' }
任务 1,任务 2,任务 3
,部分任务需要前置 loginTask