| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-03-01 19:27:26 |
| 4 | * @LastEditTime: 2025-03-19 15:41:06 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: 应用 |
| 7 | */ |
| 8 | import { Injectable } from '@nestjs/common'; |
| 9 | import * as yaml from 'yaml'; |
| 10 | |
| 11 | async function parseYml(url: string): Promise<any> { |
| 12 | try { |
| 13 | const response = await fetch(url); |
| 14 | if (!response.ok) { |
| 15 | throw new Error(`Failed to fetch ${url}: ${response.status}`); |
| 16 | } |
| 17 | const text = await response.text(); |
| 18 | return yaml.parse(text.replace(/\\/g, '')); |
| 19 | } catch (error) { |
| 20 | console.error(`YAML解析失败: ${url}`, error); |
| 21 | throw error; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | @Injectable() |
| 26 | export class AppService { |
| 27 | async getDownUrl() { |
| 28 | const winYml = 'https://ylzsfile.yikart.cn/att/latest.yml'; |
| 29 | const macYml = 'https://ylzsfile.yikart.cn/att/latest-mac.yml'; |
| 30 | |
| 31 | const [winYmlJson, macYmlJson] = await Promise.all([ |
| 32 | parseYml(winYml), |
| 33 | parseYml(macYml), |
| 34 | ]); |
| 35 | |
| 36 | return { |
| 37 | win: winYmlJson, |
| 38 | mac: macYmlJson, |
| 39 | hostUrl: 'https://ylzsfile.yikart.cn/att/', |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | getHello(): string { |
| 44 | return 'Hello!This is 爱团团AiToEarn'; |
| 45 | } |
| 46 | } |
| 47 |