VERTEX
  • VERTEX
  • 新手入门
    • 最低配置要求
    • 安装操作
    • 更新操作
    • 登录
    • 版本说明
  • 视频教程
    • 刷流教程
    • 追剧教程
    • 自动追番
  • 配置流程
    • 刷流配置流程
    • 追剧配置流程
  • 常见问题
    • 常见问题
  • 主要模块
    • 信息监控
    • 站点
    • 下载器
    • 服务器
    • Rss 任务
    • Rss 规则
    • 删种规则
    • 选种规则
    • 链接规则
    • 全局设置
    • 定时脚本
    • 通知工具
  • 刷流
    • 已支持的站点
  • 追剧
    • 微信联动
    • 超级追剧模式
    • 媒体服务通知
  • 其它
    • 使用须知
    • 各类规则判断条件中的比较类型
    • PT 扫盲
    • Cron 表达式
由 GitBook 提供支持
在本页
  • 例子
  • 按照剩余空间限速
  • 定时备份至指定路径下
  • 定时备份至 Webdav
  1. 主要模块

定时脚本

例子

按照剩余空间限速

async () => {
  // 下载器 ID ['id1', 'id2', 'id3']
  const clientIds = ['21d08858'];
  // 限速, 单位 Byte
  const limitSpeed = 10 * 1024 * 1024;
  // 最小剩余空间, 单位 Byte
  const minFreeSpace = 20 * 1024 * 1024 * 1024;
  for (const clientId of clientIds) {
    const client = global.runningClient[clientId];
    // 获取下载器当前剩余空间以及当前限速信息
    const freeSpace = client.maindata.freeSpaceOnDisk;
    const limit = await client.getGlobalSpeedLimit('download');
    if (freeSpace < minFreeSpace) {
      if (+limit === limitSpeed) {
        continue;
      }
      logger.info(`定时脚本 ${this.alias} 达到限速标准, 执行限速`);
      await client.setGlobalSpeedLimit('download', limitSpeed);
    } else {
      if (+limit !== 0) {
        logger.info(`定时脚本 ${this.alias} 未达到限速标准, 恢复限速`);
        await client.setGlobalSpeedLimit('download', 0);
      }
    }
  }
}

定时备份至指定路径下

async () => {
  // 希望备份到的目录, 需映射至 docker
  const baseDir = '/';
  const fs = require('fs');
  const path = require('path');

  try {
    const backupFilename = await (new (require('../model/SettingMod'))()).backupVertex({});
    fs.copyFileSync(backupFilename, path.join(baseDir, path.basename(backupFilename)));
    logger.sc('备份成功,', backupFilename);
  } catch (e) {
    logger.error('备份失败, 错误信息:\n', e);
  }
};

定时备份至 Webdav

async () => {
  // 用户名
  const username = 'username';
  // 密码
  const password = 'password';
  // 希望上传到的目录
  const baseDir = '/';
  // webdav url
  const url = 'http://webdav.vertex.icu/';

  const { createClient } = require('webdav');
  const fs = require('fs');
  const path = require('path');

  const client = createClient(
    url,
    {
      username: username,
      password: password
    }
  );
  try {
    const backupFilename = await (new (require('../model/SettingMod'))()).backupVertex({});
    await client.putFileContents(path.join(baseDir, path.basename(backupFilename)), fs.readFileSync(backupFilename, { encoding: null }));
    logger.sc('备份成功,', backupFilename);
  } catch (e) {
    logger.error('备份失败, 错误信息:\n', e);
  }
};