當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript shiorif.Shiorif類代碼示例

本文整理匯總了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}`);
    }
  }
開發者ID:Ikagaka,項目名稱:ghost-kernel.js,代碼行數:35,代碼來源:VersionService.ts

示例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]));
   }
 }
開發者ID:Ikagaka,項目名稱:ghost-kernel.js,代碼行數:15,代碼來源:ShioriResourcesService.ts

示例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());
 }
開發者ID:Ikagaka,項目名稱:ghost-kernel.js,代碼行數:15,代碼來源:SakuraScriptExecuterService.ts

示例4: getUsername

 async getUsername() {
   this.shioriResources.username = (await this.shiorif.request3("GET", "username")).response.to("3.0").headers.Value;
 }
開發者ID:Ikagaka,項目名稱:ghost-kernel.js,代碼行數:3,代碼來源:ShioriResourcesService.ts


注:本文中的shiorif.Shiorif類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。