Commit b8055429 authored by 神楽坂玲奈's avatar 神楽坂玲奈

新的账号系统

parent de224bfc
import {Injectable, ApplicationRef, EventEmitter, NgZone} from '@angular/core';
import {ApplicationRef, EventEmitter, Injectable, NgZone} from '@angular/core';
import {Http, URLSearchParams} from '@angular/http';
import * as crypto from 'crypto';
import {App, AppStatus, Action} from './app';
import {Action, App, AppStatus} from './app';
import {SettingsService} from './settings.sevices';
import * as fs from 'fs';
import {createReadStream, createWriteStream} from 'fs';
......@@ -65,7 +65,7 @@ export class AppsService {
private downloadService: DownloadService, private ngZone: NgZone, private loginService: LoginService) {
}
get lastVisited(): App|undefined {
get lastVisited(): App | undefined {
let id = localStorage.getItem('last_visited');
if (id) {
return this.apps.get(id);
......@@ -73,7 +73,7 @@ export class AppsService {
return undefined;
}
set lastVisited(app: App|undefined) {
set lastVisited(app: App | undefined) {
if (app) {
localStorage.setItem('last_visited', app.id);
}
......@@ -96,11 +96,12 @@ export class AppsService {
localStorage.setItem('apps_json', JSON.stringify(data));
this.apps = this.loadAppsList(data);
} catch (e) {
console.error(e);
let data = localStorage.getItem('apps_json');
if (data) {
this.apps = this.loadAppsList(JSON.parse(data));
} else {
alert('读取游戏列表失败,可能是网络不通')
alert('读取游戏列表失败,可能是网络不通');
this.apps = new Map();
}
}
......@@ -385,7 +386,7 @@ export class AppsService {
let interval = setInterval(() => {
}, 500);
await new Promise((resolve, reject) => {
this.ngZone.runOutsideAngular(async() => {
this.ngZone.runOutsideAngular(async () => {
try {
for (let [file, checksum] of sortedFiles) {
let src = path.join(appPath, file);
......@@ -443,7 +444,7 @@ export class AppsService {
let filePath = path.join(app.local!.path, file);
// 如果文件不存在,随便生成一个checksum
await new Promise((resolve, reject) => {
fs.access(filePath, fs.constants.F_OK, async(err: Error) => {
fs.access(filePath, fs.constants.F_OK, async (err: Error) => {
if (err) {
result.set(file, Math.random().toString());
} else if (checksum === '') {
......@@ -478,14 +479,14 @@ export class AppsService {
try {
Logger.info('Checking updating: ', app);
let latestFiles = await this.getChecksumFile(app);
let localFiles: Map<string, string>|undefined;
let localFiles: Map<string, string> | undefined;
if (verify) {
// 刷新进度条
let interval = setInterval(() => {
}, 500);
app.status.total = latestFiles.size;
await new Promise((resolve, reject) => {
this.ngZone.runOutsideAngular(async() => {
this.ngZone.runOutsideAngular(async () => {
try {
localFiles = await this.verifyFiles(app, latestFiles, () => {
app.status.progress += 1;
......@@ -667,7 +668,7 @@ export class AppsService {
async install(app: App, option: InstallOption) {
const tryToInstall = async(task: InstallTask): Promise<void> => {
const tryToInstall = async (task: InstallTask): Promise<void> => {
if (!task.app.readyForInstall()) {
await new Promise((resolve, reject) => {
this.eventEmitter.subscribe(() => {
......@@ -681,7 +682,7 @@ export class AppsService {
}
await this.doInstall(task);
};
const addDownloadTask = async(_app: App, dir: string): Promise<{app: App, files: string[]} > => {
const addDownloadTask = async (_app: App, dir: string): Promise<{ app: App, files: string[] }> => {
let locale = this.settingsService.getLocale();
if (!['zh-CN', 'en-US', 'ja-JP'].includes(locale)) {
locale = 'en-US';
......@@ -981,7 +982,7 @@ export class AppsService {
}
}
await new Promise((resolve, reject) => {
this.ngZone.runOutsideAngular(async() => {
this.ngZone.runOutsideAngular(async () => {
try {
await this.backupFiles(app.parent!.local!.path, backupPath, conflictFiles, (n) => {
app.status.progress += 1;
......@@ -1134,7 +1135,7 @@ export class AppsService {
async backupFiles(dir: string, backupDir: string, files: Iterable<string>, callback?: (progress: number) => void) {
let n = 0;
for (let file of files) {
await new Promise(async(resolve, reject) => {
await new Promise(async (resolve, reject) => {
let srcPath = path.join(dir, file);
let backupPath = path.join(backupDir, file);
await this.createDirectory(path.dirname(backupPath));
......@@ -1166,7 +1167,7 @@ export class AppsService {
}
}
async getChecksumFile(app: App): Promise<Map<string, string> > {
async getChecksumFile(app: App): Promise<Map<string, string>> {
let locale = this.settingsService.getLocale();
if (!['zh-CN', 'en-US', 'ja-JP'].includes(locale)) {
......@@ -1245,7 +1246,7 @@ export class AppsService {
let interval = setInterval(() => {
}, 500);
await new Promise((resolve, reject) => {
this.ngZone.runOutsideAngular(async() => {
this.ngZone.runOutsideAngular(async () => {
try {
for (let file of files) {
app.status.progress += 1;
......
......@@ -166,7 +166,7 @@ export class LobbyComponent implements OnInit {
}
get grouped_apps() {
let contains = ['game', 'music', 'book', 'test'].map((value) => Category[value]);
let contains = ['game', 'music', 'book'].map((value) => Category[value]);
let result = {runtime: []};
for (let app of this.apps.values()) {
let tag: string;
......
......@@ -19,13 +19,13 @@ export class LoginComponent {
url: string;
readonly return_sso_url = 'https://mycard.moe/login_callback'; // 这个url不会真的被使用,可以填写不存在的
constructor (private loginService: LoginService) {
constructor(private loginService: LoginService) {
let params = new URLSearchParams();
params.set('return_sso_url', this.return_sso_url);
let payload = Buffer.from(params.toString()).toString('base64');
let url = new URL('https://ygobbs.com/session/sso_provider');
let url = new URL('https://accounts.moecube.com');
params = url['searchParams'];
params.set('sso', payload);
params.set('sig', crypto.createHmac('sha256', 'zsZv6LXHDwwtUAGa').update(payload).digest('hex'));
......@@ -39,13 +39,13 @@ export class LoginComponent {
// 暂时 hack 一下登出,因为聊天室现在没办法重新初始化,于是登出后刷新页面。
params.set('redirect', 'https://mycard.moe/logout_callback');
this.url = url.toString()
this.url = url.toString();
}
}
return_sso (return_url: string) {
return_sso(return_url: string) {
if (return_url === 'https://mycard.moe/logout_callback') {
return location.reload()
return location.reload();
}
if (!return_url.startsWith(this.return_sso_url)) {
return;
......@@ -55,7 +55,7 @@ export class LoginComponent {
this.loginService.login(user);
}
toObject (entries: Iterable<[string, any]>): any {
toObject(entries: Iterable<[string, any]>): any {
let result = {};
for (let [key, value] of entries) {
result[key] = value;
......@@ -63,7 +63,7 @@ export class LoginComponent {
return result;
}
openExternal (url: string) {
openExternal(url: string) {
shell.openExternal(url);
}
}
......@@ -60,6 +60,16 @@
<source>随机</source>
<target>Random</target>
</trans-unit>
<trans-unit datatype="html" id="5018459a548611c5e7a8bb9f81f8871358089f69">
<source>正在读取游戏列表...</source>
<target>Loading Game List...</target>
</trans-unit>
<trans-unit datatype="html" id="dc0c986dacfc57a3254d4164784a43c8c78cd5ef">
<source>现在没有等待中的游戏,可以自行创建一个房间或者去匹配</source>
<target>There is no opening game available now, you can create a new game yourself, or play ranked game.</target>
</trans-unit>
<trans-unit datatype="html" id="e35d1bf7c735e8df55a62046cd2d9f820bf5bffd">
<source>游戏标题</source>
......@@ -220,6 +230,11 @@
<source><x id="INTERPOLATION"/> 购买</source>
<target><x id="INTERPOLATION"/> Buy</target>
</trans-unit>
<trans-unit datatype="html" id="0415ea4132361a518cfb8b81e058f4238b85f071">
<source>安装试玩版</source>
<target>Install Trial Version</target>
</trans-unit>
<trans-unit datatype="html" id="a8cae935472a05e1c8c9be436bb7b1bdea96a54a">
<source>安装</source>
......@@ -450,6 +465,11 @@
<source>购买</source>
<target>Buy</target>
</trans-unit>
<trans-unit datatype="html" id="e81bc577e08b01e7ebe9351760c0c845b3bb2fb4">
<source>返回</source>
<target>Return</target>
</trans-unit>
<trans-unit datatype="html" id="ef65da47763167a418e811d9007c53b896b50479">
<source>最小化</source>
......
{
"name": "mycard",
"version": "3.0.26",
"version": "3.1.0",
"description": "mycard",
"keywords": [],
"author": "zh99998 <zh99998@gmail.com>",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment