@/store#IYUUStore TypeScript Examples

The following examples show how to use @/store#IYUUStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: backup.ts    From IYUU-GUI with GNU Affero General Public License v3.0 6 votes vote down vote up
// 入口方法,内部根据字符串信息判断是使用jsonar库解析PHP Array还是JSON解析
    public static decodeFromFile(file: File) {
        return new Promise((resolve, reject) => {
            const r = new FileReader();
            r.onload = (e) => {
                // @ts-ignore
                const content: string = e.target.result

                let parsedConfig;
                if (content.indexOf('<?php') > -1) {
                    parsedConfig = this.decodeFromPHPArrayString(content)
                } else {
                    parsedConfig = decodeFromJsonString(content)
                }

                if (parsedConfig['iyuu.cn'] === IYUUStore.token) {
                    resolve(parsedConfig)
                } else {
                    reject('配置项未通过检验,或你传入文件中的爱语飞飞令牌与当前登录的不符。')
                }
            }
            r.readAsText(file);
        })
    }
Example #2
Source File: backup.ts    From IYUU-GUI with GNU Affero General Public License v3.0 6 votes vote down vote up
public static decodeFromFile(file:File) {
        return new Promise((resolve, reject) => {
            const r = new FileReader();
            r.onload = (e) => {
                // @ts-ignore
                const content: string = e.target.result

                let parsedConfig = decodeFromJsonString(content);

                if (parsedConfig['token'] === IYUUStore.token) {
                    resolve(parsedConfig)
                } else {
                    reject('配置项未通过检验,或你传入文件中的爱语飞飞令牌与当前登录的不符。')
                }
            }
            r.readAsText(file);
        })
    }
Example #3
Source File: backup.ts    From IYUU-GUI with GNU Affero General Public License v3.0 6 votes vote down vote up
public static importFromJSON(config: any) {
        IYUUStore.restoreFromConfig({
            token: config.token,
            sites: config.sites,
            clients: config.clients,
            apiPreInfoHash: config.config.apiPreInfoHash,
            maxRetry: config.config.maxRetry,
            weChatNotify: config.config.weChatNotify
        })
        StatusStore.restoreFromConfig({
            reseedTorrentCount: config.state.reseedTorrentCount,
            startAppCount: config.state.startAppCount,
            startMissionCount: config.state.startMissionCount,
        })
        MissionStore.restoreFromConfig({
            reseeded: config.hashes.reseeded
        })
    }
Example #4
Source File: backup.ts    From IYUU-GUI with GNU Affero General Public License v3.0 6 votes vote down vote up
public static exportToJSON() {
        const exportJSON =  {
            version: packageInfo.version,
            token: IYUUStore.token,
            sites: IYUUStore.enable_sites,
            clients: IYUUStore.enable_clients,
            state: {
                startAppCount: StatusStore.startAppCount,
                startMissionCount: StatusStore.startMissionCount,
                reseedTorrentCount: StatusStore.reseedTorrentCount
            },
            hashes: {
                reseeded: MissionStore.reseeded
            },
            config: {
                apiPreInfoHash: IYUUStore.apiPreInfoHash,
                maxRetry: IYUUStore.maxRetry,
                weChatNotify: IYUUStore.weChatNotify
            }
        }

        const blob = new Blob([JSON.stringify(exportJSON)], {
            type: "text/plain;charset=utf-8"
        })
        FileSaver.saveAs(blob, "iyuu_config.json");
    }
Example #5
Source File: iyuu.ts    From IYUU-GUI with GNU Affero General Public License v3.0 6 votes vote down vote up
// 用户登录绑定操作
    userLogin(userLoginForm: Forms.userLoginRequest): Promise<Forms.userLoginResponse> {
        // 要求对合作站点用户密钥进行sha1操作 sha1(passkey)
        userLoginForm.passkey = sha1(userLoginForm.passkey)

        return new Promise((resolve, reject) => {
            this.instance.get('/user/login', {
                params: userLoginForm
            }).then(resp => {
                const data: Forms.userLoginResponse = resp.data
                if (data.ret === 200) {
                    Notification.success({
                        title: '登录验证成功',
                        message: data.data.errmsg
                    })
                    IYUUStore.setToken(userLoginForm.token).then(() => {
                        resolve(data)
                    })
                } else {
                    reject(data)
                }
            })
        })
    }
Example #6
Source File: iyuu.ts    From IYUU-GUI with GNU Affero General Public License v3.0 6 votes vote down vote up
// 获取所有站点支持列表
    apiSites(userLoginForm: Forms.userLoginRequest | null = null): Promise<Forms.apiSitesResponse> {
        let sign: string;
        if (userLoginForm === null) {
            sign = this.getSign()
        } else {
            sign = userLoginForm.token
        }

        return new Promise((resolve, reject) => {
            this.instance.get('/api/sites', {
                params: {
                    sign: sign,
                    version: this.version
                } as Forms.apiSitesRequest
            }).then(resp => {
                const data: Forms.apiSitesResponse = resp.data

                if (data.data.sites) {
                    Notification.success('从IYUU服务器获取站点数据成功')
                    IYUUStore.updateSites(data.data.sites).then(() => {
                        resolve(data)
                    })
                } else {
                    // TODO cleanToken
                    reject(data)
                }
            })
        })
    }
Example #7
Source File: index.ts    From IYUU-GUI with GNU Affero General Public License v3.0 6 votes vote down vote up
router.beforeEach((to, from, next) => {
  // @ts-ignore
  if (to.matched.some(record => record.meta.requiresLogin) && !IYUUStore.token) {
    Notification.error('未登录,返回登录窗口')
    next('/login')
  } else {
    next()
  }
})
Example #8
Source File: backup.ts    From IYUU-GUI with GNU Affero General Public License v3.0 5 votes vote down vote up
public static importFromJSON(config: any) {
        let clientCount = 0;
        let siteCount = 0;

        const clients: any[] = config.default.clients;
        for (let i = 0; i < clients.length; i++) {
            const client = clients[i]
            // 构造config
            let mergedClientConfig: TorrentClientConfig = {
                type: client.type.toLowerCase(),
                name: client.type,
                uuid: UUID.v4(),
                address: client.host,
                username: client.username,
                password: client.password,
                timeout: (client.type === 'transmission' ? 60 * 2 : 60) * 1e3
            }

            // 通过地址判断是不是有重复
            if (IYUUStore.enable_clients.findIndex(c => c.address === mergedClientConfig.address) === -1) {
                IYUUStore.addEnableClient(mergedClientConfig)
                clientCount++
            }
        }

        // 遍历我们的未添加sites列表
        for (let j = 0; j < IYUUStore.unsignedSites.length; j++) {
            let site = IYUUStore.unsignedSites[j]
            let mergedSiteConfig: EnableSite = _.merge(site,{
                cookies: "",
                download_torrent: false,
                link: "",
                rate_limit: {maxRequests: 0, requestsDelay: 0},
            })
            if (site.site in config) {
                const siteConfigFromPHP = config[site.site]

                // 如果没有cookies和passkey,直接跳过
                if (!siteConfigFromPHP.cookies && !siteConfigFromPHP.passkey) {
                    continue
                }

                mergedSiteConfig.cookies = siteConfigFromPHP.cookies
                mergedSiteConfig.download_torrent = isForceDownloadSite(site.site)
                let link = IYUUStore.siteDownloadLinkTpl(site.site)
                if (siteConfigFromPHP.passkey) {
                    link = link.replace(/{passkey}/ig, siteConfigFromPHP.passkey)
                }
                if (siteConfigFromPHP.url_replace) {
                    for (const [key, value] of Object.entries(siteConfigFromPHP.url_replace)) {
                        if (typeof value === "string") {
                            link = link.replaceAll(key, value)
                        }
                    }
                }

                if (siteConfigFromPHP.url_join) {
                    link += (link.lastIndexOf('?') > -1 ? '&' : '?' ) + siteConfigFromPHP.url_join.join('&')
                }

                if (siteConfigFromPHP.limitRule) {
                    mergedSiteConfig.rate_limit.maxRequests = siteConfigFromPHP.limitRule.count || 0
                    mergedSiteConfig.rate_limit.requestsDelay = siteConfigFromPHP.limitRule.sleep || 0
                }

                if (!link.match(/({[^}]+?})/ig) && link.search('{}') > -1) {
                    mergedSiteConfig.link = link
                    IYUUStore.addEnableSite(mergedSiteConfig)
                    siteCount++
                }
            }
        }

        return {client: clientCount, site: siteCount}
    }
Example #9
Source File: iyuu.ts    From IYUU-GUI with GNU Affero General Public License v3.0 5 votes vote down vote up
getSign():string {
        // @ts-ignore
        return IYUUStore.token
    }