本文整理匯總了TypeScript中shiorif.Shiorif類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Shiorif類的具體用法?TypeScript Shiorif怎麽用?TypeScript Shiorif使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Shiorif類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getShioriVersionInfo
/**
* SSPと同様の方式でバージョン情報を取得する
*
* 注意: このメソッドはshiorif.autoConvertRequestVersionを変更します。
*/
static async getShioriVersionInfo(shiorif: Shiorif) {
shiorif.autoConvertRequestVersion = "2.6";
// SHIORI/2.6 GET Versionを問い合わせる
const { response } = await shiorif.getVersion2();
const code = response.status_line.code;
const version = response.status_line.version;
if (!version) throw new Error("no shiori protocol version");
if (code === 200 && /2\.\d/.test(version)) {
// SHIORI/2.6で返ってきたらそのまま読む
const header = response.headers.header;
const _version = "2.6";
const name = header.ID || "";
const craftman = header.Craftman || "";
return new ShioriVersionInfo(name, _version, craftman, craftman);
} else if (/3\.\d/.test(version)) {
// SHIORI/3.0で返ってきたら以後SHIORI/3.0で通信することにし、取り直す
shiorif.autoConvertRequestVersion = "3.0";
const [_version, name, craftman, craftmanw] = await Promise.all([
(await shiorif.request3("GET", "version")).response.headers.Value as string,
(await shiorif.request3("GET", "name")).response.headers.Value as string,
(await shiorif.request3("GET", "craftman")).response.headers.Value as string,
(await shiorif.request3("GET", "craftmanw")).response.headers.Value as string,
]);
return new ShioriVersionInfo(name, _version, craftman, craftmanw);
} else {
throw new Error(`unknown shiori protocol version: ${version}`);
}
}
示例2: getSites
async getSites(
type: "sakura.recommendsites" | "sakura.portalsites" | "kero.recommendsites",
) {
let sites: Sites;
switch (type) {
case "sakura.recommendsites": sites = this.shioriResources.sakura.recommendsites; break;
case "sakura.portalsites": sites = this.shioriResources.sakura.portalsites; break;
default: sites = this.shioriResources.kero.recommendsites;
}
sites.length = 0; // clear
for (const site of (await this.shiorif.get3(type)).response.headers.ValueSeparated2()) {
// tslint:disable-next-line no-magic-numbers
sites.push(new SiteMenu(site[0], site[1], site[2], site[3]));
}
}
示例3: execute
async execute(transaction: ShioriTransaction) {
let value = transaction.response.to("3.0").headers.Value;
const requestHeaders = transaction.request.to("3.0").headers;
// OnTranslate
const translateTransaction = await this.shiorif.get3("OnTranslate", [
value || "",
"", // TODO: Reference1
requestHeaders.ID as string,
requestHeaders.references().join("\x01"),
]);
const translateResponse = translateTransaction.response.to("3.0");
if (translateResponse.status_line.code === 200) value = translateResponse.headers.Value;
// tslint:disable-next-line no-null-keyword
if (value != null) await this.sakuraScriptExecuter.execute(value.toString());
}
示例4: getUsername
async getUsername() {
this.shioriResources.username = (await this.shiorif.request3("GET", "username")).response.to("3.0").headers.Value;
}