本文整理汇总了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;
}