| 579 | } |
| 580 | |
| 581 | async enableScripts(param: { uuids: string[]; enable: boolean }) { |
| 582 | const { uuids, enable } = param; |
| 583 | const logger = this.logger.with({ uuids, enable }); |
| 584 | const scripts = await this.scriptDAO.gets(uuids); |
| 585 | const uuids2: string[] = []; |
| 586 | for (let i = 0, l = uuids.length; i < l; i++) { |
| 587 | const script = scripts[i]; |
| 588 | if (script && script.uuid && script.uuid === uuids[i]) { |
| 589 | uuids2.push(script.uuid); |
| 590 | } |
| 591 | } |
| 592 | if (!uuids2.length) { |
| 593 | logger.error("scripts not found"); |
| 594 | throw new Error("scripts not found"); |
| 595 | } |
| 596 | return this.scriptDAO |
| 597 | .updates(uuids2, { |
| 598 | status: enable ? SCRIPT_STATUS_ENABLE : SCRIPT_STATUS_DISABLE, |
| 599 | updatetime: Date.now(), |
| 600 | }) |
| 601 | .then(() => { |
| 602 | logger.info("enable success"); |
| 603 | this.mq.publish<TEnableScript[]>( |
| 604 | "enableScripts", |
| 605 | uuids2.map((uuid) => ({ uuid, enable })) |
| 606 | ); |
| 607 | return {}; |
| 608 | }) |
| 609 | .catch((e) => { |
| 610 | logger.error("enable error", Logger.E(e)); |
| 611 | throw e; |
| 612 | }); |
| 613 | } |
| 614 | |
| 615 | async fetchInfo(uuid: string) { |
| 616 | const script = await this.scriptDAO.get(uuid); |