Skip to content

Commit

Permalink
fix: リファクタリングミス修正
Browse files Browse the repository at this point in the history
  • Loading branch information
taizod1024 committed Jun 5, 2024
1 parent dbd6186 commit 659ef79
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 59 deletions.
14 changes: 7 additions & 7 deletions src/XExtensionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class XExtensionHelper {
// check
const config = vscode.workspace.getConfiguration(acts.appcfgkey + "." + lang);
const cmd = config.checker || "";
acts.channel.appendLine(`[${acts.timestamp()}] checker: ${cmd}`);
acts.channel.appendLine(`checker: ${cmd}`);
if (!cmd) {
throw "ERROR: no checker";
}
Expand All @@ -23,23 +23,23 @@ class XExtensionHelper {
}
const out = fs.readFileSync(acts.tmpstdoutfile).toString().trim().replace(/\r\n/g, "\n").replace(/\n/g, "\r\n");
fs.unlinkSync(acts.tmpstdoutfile);
acts.channel.appendLine(`[${acts.timestamp()}] - stdout="${out}"`);
acts.channel.appendLine(`- stdout="${out}"`);
}

compileTask(lang: string, opt: object = {}): void {
// compile
const config = vscode.workspace.getConfiguration(acts.appcfgkey + "." + lang);
const cmd = config.compiler || "";
if (!cmd) {
acts.channel.appendLine(`[${acts.timestamp()}] compiler: ${cmd}`);
acts.channel.appendLine(`compiler: ${cmd}`);
} else {
let deleted = false;
if (fs.existsSync(acts.execfile)) {
fs.unlinkSync(acts.execfile);
deleted = true;
}
acts.channel.appendLine(`[${acts.timestamp()}] execfile: ${acts.execfile}${deleted ? " deleted" : ""}`);
acts.channel.appendLine(`[${acts.timestamp()}] compiler: ${cmd}`);
acts.channel.appendLine(`execfile: ${acts.execfile}${deleted ? " deleted" : ""}`);
acts.channel.appendLine(`compiler: ${cmd}`);
const cmdexp = acts.expandString(cmd);
// 標準エラー出力のリダイレクトをwindowsとwsl2で同じように扱えないため標準出力のみを扱う
const command = `(${cmdexp}) > ${acts.tmpstdoutfile}`;
Expand All @@ -52,13 +52,13 @@ class XExtensionHelper {
} finally {
const out = fs.readFileSync(acts.tmpstdoutfile).toString().trim().replace(/\r\n/g, "\n").replace(/\n/g, "\r\n");
fs.unlinkSync(acts.tmpstdoutfile);
acts.channel.appendLine(`[${acts.timestamp()}] - stdout="${out}"`);
acts.channel.appendLine(`- stdout="${out}"`);
}
}

// show executor
const cmdexe = config.executor || "";
acts.channel.appendLine(`[${acts.timestamp()}] executor: ${cmdexe}`);
acts.channel.appendLine(`executor: ${cmdexe}`);
if (!cmdexe) {
throw "ERROR: no executor";
}
Expand Down
78 changes: 39 additions & 39 deletions src/xsite/AtCoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class AtCoder implements XSite {
}
// atcoderでc/c++の場合
if (this.extension === cpp.extension) {
acts.channel.appendLine(`[${acts.timestamp()}] aclibpath: ${this.aclibpath}`);
acts.channel.appendLine(`aclibpath: ${this.aclibpath}`);
// .aclibpathがない場合
if (!fs.existsSync(this.aclibpath)) {
// ダウンロード済atcoder libraryがあれば削除
Expand All @@ -237,7 +237,7 @@ class AtCoder implements XSite {
fs.rmSync(this.aclibzip_extractpath, { recursive: true, force: true });
}
// atcoder libraryをダウンロード
acts.channel.appendLine(`[${acts.timestamp()}] get_aclib: ${this.acliburl}`);
acts.channel.appendLine(`get_aclib: ${this.acliburl}`);
const agent = superagent.agent();
let response;
try {
Expand All @@ -248,9 +248,9 @@ class AtCoder implements XSite {
.catch(res => {
throw acts.responseToMessage(res);
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${response.status}`);
acts.channel.appendLine(`-> ${response.status}`);
} catch (ex) {
acts.channel.appendLine(`[${acts.timestamp()}] -> ${ex}`);
acts.channel.appendLine(`-> ${ex}`);
}
// ダウンロードできた場合だけファイルに保存して展開
if (response.status === 200) {
Expand All @@ -259,7 +259,7 @@ class AtCoder implements XSite {
// atcoderフォルダだけプロジェクトフォルダにコピー
fs.mkdirSync(this.aclibpath, { recursive: true });
fs.readdirSync(this.aclibzip_aclibpath).forEach(filename => {
acts.channel.appendLine(`[${acts.timestamp()}] aclib: ${filename}`);
acts.channel.appendLine(`aclib: ${filename}`);
const src = path.normalize(`${this.aclibzip_aclibpath}/${filename}`);
const dst = path.normalize(`${this.aclibpath}/${filename}`);
fs.copyFileSync(src, dst);
Expand All @@ -277,25 +277,25 @@ class AtCoder implements XSite {

public async loginSiteAsync() {
// show channel
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.loginurl: ${this.loginurl}`);
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.username: ${this.username}`);
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.password: ********`);
acts.channel.appendLine(`atcoder.loginurl: ${this.loginurl}`);
acts.channel.appendLine(`atcoder.username: ${this.username}`);
acts.channel.appendLine(`atcoder.password: ********`);

// get agent
const agent = superagent.agent();

// login get
acts.channel.appendLine(`[${acts.timestamp()}] login_get:`);
acts.channel.appendLine(`login_get:`);
const res1 = await agent
.get(this.loginurl)
.proxy(acts.proxy)
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res1.status}`);
acts.channel.appendLine(`-> ${res1.status}`);

// login post
acts.channel.appendLine(`[${acts.timestamp()}] login_post:`);
acts.channel.appendLine(`login_post:`);
const $ = cheerio.load(res1.text);
const csrf_token = $("input").val();
const res2 = await agent
Expand All @@ -310,7 +310,7 @@ class AtCoder implements XSite {
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res2.status}`);
acts.channel.appendLine(`-> ${res2.status}`);

// check login
if (res2.text.indexOf(`ようこそ、${this.username} さん。`) < 0) {
Expand All @@ -320,25 +320,25 @@ class AtCoder implements XSite {

public async getTestAsync() {
// show channel
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.taskurl: ${this.taskurl}`);
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.username: ${this.username}`);
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.password: ********`);
acts.channel.appendLine(`atcoder.taskurl: ${this.taskurl}`);
acts.channel.appendLine(`atcoder.username: ${this.username}`);
acts.channel.appendLine(`atcoder.password: ********`);

// get agent
const agent = superagent.agent();

// login get
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.login_get:`);
acts.channel.appendLine(`atcoder.login_get:`);
const res1 = await agent
.get(this.loginurl)
.proxy(acts.proxy)
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res1.status}`);
acts.channel.appendLine(`-> ${res1.status}`);

// login post
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.login_post:`);
acts.channel.appendLine(`atcoder.login_post:`);
const $ = cheerio.load(res1.text);
const csrf_token = $("input").val();
const res2 = await agent
Expand All @@ -353,22 +353,22 @@ class AtCoder implements XSite {
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res2.status}`);
acts.channel.appendLine(`-> ${res2.status}`);

// check login
if (res2.text.indexOf(`ようこそ、${this.username} さん。`) < 0) {
throw `ERROR: atcoder login failed, userame="${this.username}", password="********", csrf_token="${csrf_token}"`;
}

// get task
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.get_task:`);
acts.channel.appendLine(`atcoder.get_task:`);
const response = await agent
.get(this.taskurl)
.proxy(acts.proxy)
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${response.status}`);
acts.channel.appendLine(`-> ${response.status}`);

// response to test text
let text = "";
Expand All @@ -394,26 +394,26 @@ class AtCoder implements XSite {

public async submitTaskAsync() {
// show channel
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.taskurl: ${this.taskurl}`);
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.username: ${this.username}`);
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.password: ********`);
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.submiturl: ${this.submiturl}`);
acts.channel.appendLine(`atcoder.taskurl: ${this.taskurl}`);
acts.channel.appendLine(`atcoder.username: ${this.username}`);
acts.channel.appendLine(`atcoder.password: ********`);
acts.channel.appendLine(`atcoder.submiturl: ${this.submiturl}`);

// get agent
const agent = superagent.agent();

// login get
acts.channel.appendLine(`[${acts.timestamp()}] login_get:`);
acts.channel.appendLine(`login_get:`);
const res1 = await agent
.get(this.loginurl)
.proxy(acts.proxy)
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res1.status}`);
acts.channel.appendLine(`-> ${res1.status}`);

// login post
acts.channel.appendLine(`[${acts.timestamp()}] login_post:`);
acts.channel.appendLine(`login_post:`);
const $ = cheerio.load(res1.text);
const csrf_token = $("input").val();
const res2 = await agent
Expand All @@ -428,15 +428,15 @@ class AtCoder implements XSite {
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res2.status}`);
acts.channel.appendLine(`-> ${res2.status}`);

// check login
if (res2.text.indexOf(`ようこそ、${this.username} さん。`) < 0) {
throw `ERROR: atcoder login failed, userame="${this.username}", password="${this.password}", csrf_token="${csrf_token}"`;
}

// submit task
acts.channel.appendLine(`[${acts.timestamp()}] submit_task:`);
acts.channel.appendLine(`submit_task:`);
const code = fs.readFileSync(acts.taskfile).toString();
const res3 = await agent
.post(this.submiturl)
Expand All @@ -451,12 +451,12 @@ class AtCoder implements XSite {
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res3.status}`);
acts.channel.appendLine(`[${acts.timestamp()}] submissionsurl: ${this.submissionsurl}`);
acts.channel.appendLine(`-> ${res3.status}`);
acts.channel.appendLine(`submissionsurl: ${this.submissionsurl}`);
}

public browseTask() {
acts.channel.appendLine(`[${acts.timestamp()}] taskurl: ${this.taskurl}`);
acts.channel.appendLine(`taskurl: ${this.taskurl}`);
vscode.env.openExternal(vscode.Uri.parse(this.taskurl));
}

Expand Down Expand Up @@ -493,17 +493,17 @@ class AtCoder implements XSite {

// login get
this.loginurl = "https://atcoder.jp/login?continue=https%3A%2F%2Fatcoder.jp%2F&lang=ja";
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.login_get:`);
acts.channel.appendLine(`atcoder.login_get:`);
const res1 = await agent
.get(this.loginurl)
.proxy(acts.proxy)
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res1.status}`);
acts.channel.appendLine(`-> ${res1.status}`);

// login post
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.login_post:`);
acts.channel.appendLine(`atcoder.login_post:`);
const $ = cheerio.load(res1.text);
const csrf_token = $("input").val();
const res2 = await agent
Expand All @@ -518,7 +518,7 @@ class AtCoder implements XSite {
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res2.status}`);
acts.channel.appendLine(`-> ${res2.status}`);

// check login
if (res2.text.indexOf(`ようこそ、${this.username} さん。`) < 0) {
Expand All @@ -527,14 +527,14 @@ class AtCoder implements XSite {

// get language ids
this.submiturl = `https://atcoder.jp/contests/${this.contest}/submit`;
acts.channel.appendLine(`[${acts.timestamp()}] atcoder.check_valid_language_ids:`);
acts.channel.appendLine(`atcoder.check_valid_language_ids:`);
const response = await agent
.get(this.submiturl)
.proxy(acts.proxy)
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${response.status}`);
acts.channel.appendLine(`-> ${response.status}`);

const $submitpage = cheerio.load(response.text);
const languageIds = $submitpage(`#select-lang-${this.task} select.form-control`)
Expand Down
26 changes: 13 additions & 13 deletions src/xsite/Yukicoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,27 @@ class Yukicoder implements XSite {

async loginSiteAsync() {
// show channel
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.apikey: ********`);
acts.channel.appendLine(`yukicoder.apikey: ********`);
}

async getTestAsync() {
// show channel
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.problemnourl: ${this.problemnourl}`);
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.apikey: ********`);
acts.channel.appendLine(`yukicoder.problemnourl: ${this.problemnourl}`);
acts.channel.appendLine(`yukicoder.apikey: ********`);

// get agent
const agent = superagent.agent().set("accept", "application/json").set("Authorization", `Bearer ${this.apikey}`);

// get file list
let fileiurl = `${this.api_problemidurl}/file/in`;
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.fileinurl: ${fileiurl}`);
acts.channel.appendLine(`yukicoder.fileinurl: ${fileiurl}`);
const resfilei = await agent
.get(fileiurl)
.proxy(acts.proxy)
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${resfilei.status}`);
acts.channel.appendLine(`-> ${resfilei.status}`);

// get file
let text = "";
Expand All @@ -156,7 +156,7 @@ class Yukicoder implements XSite {

// get response
let fileixurl = `${this.api_problemidurl}/file/in/${fileix}`;
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.fileiurl-${nx}: ${fileixurl}`);
acts.channel.appendLine(`yukicoder.fileiurl-${nx}: ${fileixurl}`);
const resfileix = await agent
.get(fileixurl)
.proxy(acts.proxy)
Expand All @@ -165,7 +165,7 @@ class Yukicoder implements XSite {
});

let fileoxurl = `${this.api_problemidurl}/file/out/${fileix}`;
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.fileourl-${nx}: ${fileoxurl}`);
acts.channel.appendLine(`yukicoder.fileourl-${nx}: ${fileoxurl}`);
const resfileox = await agent
.get(fileoxurl)
.proxy(acts.proxy)
Expand All @@ -183,14 +183,14 @@ class Yukicoder implements XSite {

async submitTaskAsync() {
// show channel
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.problemnourl: ${this.problemnourl}`);
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.apikey: ********`);
acts.channel.appendLine(`yukicoder.problemnourl: ${this.problemnourl}`);
acts.channel.appendLine(`yukicoder.apikey: ********`);

// get agent
const agent = superagent.agent().set("accept", "application/json").set("Authorization", `Bearer ${this.apikey}`);

// submit task
acts.channel.appendLine(`[${acts.timestamp()}] yukicoder.api_submiturl: ${this.api_submiturl}`);
acts.channel.appendLine(`yukicoder.api_submiturl: ${this.api_submiturl}`);
const code = fs.readFileSync(acts.taskfile).toString();
const res3 = await agent
.post(this.api_submiturl)
Expand All @@ -201,12 +201,12 @@ class Yukicoder implements XSite {
.catch(res => {
throw `ERROR: ${acts.responseToMessage(res)}`;
});
acts.channel.appendLine(`[${acts.timestamp()}] -> ${res3.status}`);
acts.channel.appendLine(`[${acts.timestamp()}] submissionsurl: ${this.submissionsurl}`);
acts.channel.appendLine(`-> ${res3.status}`);
acts.channel.appendLine(`submissionsurl: ${this.submissionsurl}`);
}

browseTask() {
acts.channel.appendLine(`[${acts.timestamp()}] taskurl: ${this.api_problemidurl}`);
acts.channel.appendLine(`taskurl: ${this.api_problemidurl}`);
vscode.env.openExternal(vscode.Uri.parse(this.problemnourl));
}

Expand Down

0 comments on commit 659ef79

Please sign in to comment.