{"id":244,"date":"2024-09-30T22:43:42","date_gmt":"2024-09-30T14:43:42","guid":{"rendered":"https:\/\/freevipus.nyc.mn\/?p=244"},"modified":"2024-09-30T22:43:43","modified_gmt":"2024-09-30T14:43:43","slug":"backblaze-b2-%e7%a7%81%e5%af%86%e6%a1%b6-cloudflare-workers","status":"publish","type":"post","link":"https:\/\/freevipus.nyc.mn\/?p=244","title":{"rendered":"Backblaze B2 (\u79c1\u5bc6\u6876) + Cloudflare Workers\u00a0"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u73b0\u5728 Backblaze \u521b\u5efa\u6876\u7684\u7b56\u7565\u53d1\u751f\u4e86\u53d8\u5316\uff1a\u5fc5\u987b\u652f\u4ed8\u4e00\u6b21\u6027\u7684\u8d39\u7528\uff081 \u7f8e\u5200\uff09\uff0c\u6216\u8005\u8d26\u6237\u6709\u8fc7\u4ed8\u8d39\u8bb0\u5f55\u624d\u53ef\u4ee5\u521b\u5efa\u516c\u5f00\u6876\uff08\u5e94\u8be5\u662f\u9632\u6b62\u6ee5\u7528\uff09\uff0c\u5426\u5219\u53ea\u80fd\u521b\u5efa\u79c1\u5bc6\u6876 (Private Bucket)\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50a8\u5b58\u5728\u516c\u5f00\u6876\u7684\u56fe\u7247\uff0c\u76f4\u63a5\u8bbf\u95ee URL \u5c31\u80fd\u770b\u5230\u3002\u4f46\u79c1\u5bc6\u6876\u7684\u56fe\u7247\u4e0d\u884c\uff0c\u8bbf\u95ee URL \u662f\u8fd9\u4e2a\u7ed3\u679c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"864\" height=\"112\" src=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/8.png\" alt=\"\" class=\"wp-image-245\" srcset=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/8.png 864w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/8-300x39.png 300w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/8-150x19.png 150w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/8-768x100.png 768w\" sizes=\"auto, (max-width: 864px) 100vw, 864px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u65b0\u65b9\u6848\">\u65b0\u65b9\u6848<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b0\u65b9\u6848\u7684\u601d\u8def\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Backblaze B2 \u79c1\u5bc6\u6876\u5b58\u50a8\u56fe\u7247\u3002<\/li>\n\n\n\n<li>Cloudflare Worker \u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u5bc6\u94a5 (Application Key) \u5b9e\u73b0\u8ba4\u8bc1\u8bbf\u95ee Backblaze B2 \u79c1\u5bc6\u6876\uff0c\u5e76\u7f13\u5b58\u56fe\u7247\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u7528\u6237\u8bbf\u95ee\u9875\u9762\uff0c\u8bf7\u6c42\u56fe\u7247\u5730\u5740\uff0c\u89e6\u53d1 Cloudflare Worker \uff0c<\/li>\n\n\n\n<li>Worker \u7528\u5e94\u7528\u7a0b\u5e8f\u5bc6\u94a5\u7b7e\u540d\uff0c\u8bbf\u95ee Backblaze B2 \u79c1\u5bc6\u6876\uff0c<\/li>\n\n\n\n<li>Backblaze B2 \u9a8c\u8bc1\u7b7e\u540d\uff0c\u8fd4\u56de\u56fe\u7247\u7ed9 Worker \uff0c<\/li>\n\n\n\n<li>Worker \u663e\u793a\u56fe\u7247\u5230\u9875\u9762\uff0c\u7528\u6237\u770b\u5230\u56fe\u7247\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u63d0\u6761\u4ef6\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6ce8\u518c\u597d Cloudflare \u8d26\u6237<\/li>\n\n\n\n<li>\u6ce8\u518c\u597d Backblaze \u8d26\u6237<\/li>\n\n\n\n<li>\u6709\u57df\u540d\u6258\u7ba1\u5728 Cloudflare<\/li>\n\n\n\n<li>\u5b89\u88c5\u597d PicGo (\u652f\u6301 Win\/Mac\/Linux \u5e73\u53f0)<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u5f00\u59cb\u5427\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e00\u521b\u5efa-backblaze-b2-\u79c1\u5bc6\u6876\">\u4e00\u3001\u521b\u5efa Backblaze B2 \u79c1\u5bc6\u6876<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5f55 Backblaze \uff0c\u9ed8\u8ba4\u6765\u5230\u6876 (Buckets) \u9875\u9762\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u63d0\u793a\uff1aBackblaze \u7684\u4e2d\u6587\u754c\u9762\u673a\u7ffb\u5473\u9053\u5b9e\u5728\u592a\u6d53\uff0c\u8bf7\u5148\u53f3\u4e0b\u89d2\u5207\u6362\u4e3a English \u3002<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb&nbsp;<em>Create a Bucket<\/em>&nbsp;\uff0c\u5728&nbsp;<em>Bucket Unique Name<\/em>&nbsp;\u9879\u586b\u5165\u6876\u540d\u79f0\uff08\u6211\u586b\u7684 it-is-just-a-test-bucket\uff09\uff0c\u5176\u4f59\u9879\u4fdd\u6301\u9ed8\u8ba4\u5373\u53ef\u3002\u7136\u540e\u70b9\u51fb&nbsp;<kbd>Create a Bucket<\/kbd>&nbsp;\u6309\u94ae\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"816\" src=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/09.png\" alt=\"\" class=\"wp-image-246\" srcset=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/09.png 606w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/09-223x300.png 223w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/09-111x150.png 111w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u79c1\u5bc6\u6876\u751f\u6210\u4e86\u3002\u8bb0\u4e0b\u00a0<em>Endpoint<\/em>\u00a0\u7684\u503c\uff0c\u540e\u9762\u8981\u7528\u5230\u4e24\u6b21\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"684\" height=\"326\" src=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/10.png\" alt=\"\" class=\"wp-image-247\" srcset=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/10.png 684w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/10-300x143.png 300w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/10-150x71.png 150w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb\u00a0<em>Lifecycle Settings<\/em>\u00a0\uff0c\u9009\u62e9 Keep only the last version of the file \u3002\u70b9\u51fb\u00a0<kbd>Update Bucket<\/kbd>\u00a0\u6309\u94ae\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"493\" src=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/11.png\" alt=\"\" class=\"wp-image-248\" style=\"width:840px;height:auto\" srcset=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/11.png 608w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/11-300x243.png 300w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/11-150x122.png 150w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e8c\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u5bc6\u94a5-application-key\">\u4e8c\u3001\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u5bc6\u94a5 (Application Key)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb\u9875\u9762\u5de6\u4fa7\u83dc\u5355&nbsp;<em>Account<\/em>&nbsp;\u9879\u4e0b\u7684&nbsp;<em>Application Keys<\/em>&nbsp;\uff0c\u7136\u540e\u70b9\u51fb&nbsp;<em>Add a New Application Key<\/em>&nbsp;\uff0c\u5728&nbsp;<em>Name of Key<\/em>&nbsp;\u9879\u586b\u5199\u5e94\u7528\u7a0b\u5e8f\u5bc6\u94a5\u540d\u79f0\uff08\u6211\u586b\u7684 my-key-for-uploading\uff09\uff0c\u5176\u4f59\u4fdd\u6301\u9ed8\u8ba4\u5373\u53ef\u3002\u70b9\u51fb&nbsp;<kbd>Create New Key<\/kbd>&nbsp;\u6309\u94ae\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"597\" src=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/12.png\" alt=\"\" class=\"wp-image-249\" style=\"width:609px;height:auto\" srcset=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/12.png 608w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/12-300x295.png 300w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/12-150x147.png 150w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u5bc6\u94a5\u540e\uff0c\u590d\u5236\u4fe1\u606f\u4fdd\u5b58\u597d\uff08\u5173\u6389\u5c31\u4e0d\u518d\u663e\u793a\u4e86\uff01\uff09\uff0c\u540e\u9762\u8981\u7528\u5230\u4e24\u6b21\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"231\" src=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/13.png\" alt=\"\" class=\"wp-image-250\" srcset=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/13.png 678w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/13-300x102.png 300w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/13-150x51.png 150w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e09\u521b\u5efa-cloudflare-worker\">\u4e09\u3001\u521b\u5efa Cloudflare Worker<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5f55 Cloudflare \uff0c\u70b9\u51fb\u9875\u9762\u5de6\u4fa7\u83dc\u5355\u4e2d&nbsp;<em>Workers \u548c Pages<\/em>&nbsp;\uff0c\u53f3\u4fa7\u9875\u9762\u4e2d\u70b9\u51fb&nbsp;<em>\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f<\/em>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u90e8\u7f72 \u201cHello World\u201d \u811a\u672c<\/em>\u00a0\u9875\u9762\uff0c\u586b\u5165 Worker \u540d\u79f0\uff08\u6211\u586b\u7684 test-worker\uff09\uff0c\u70b9\u51fb\u00a0<kbd>\u90e8\u7f72<\/kbd>\u00a0\u6309\u94ae\uff0c\u4e00\u4e2a\u7b80\u5355\u7684 Worker \u5c31\u90e8\u7f72\u597d\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb\u00a0<kbd>\u7f16\u8f91\u4ee3\u7801<\/kbd>\u00a0\u6309\u94ae\uff0c\u5728\u9875\u9762\u4e2d\u628a\u5de6\u4fa7\u7f16\u8f91\u533a\u4e2d\u7684\u4ee3\u7801\u66ff\u6362\u4e3a\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ node_modules\/aws4fetch\/dist\/aws4fetch.esm.mjs\nvar encoder = new TextEncoder();\nvar HOST_SERVICES = {\n  appstream2: \"appstream\",\n  cloudhsmv2: \"cloudhsm\",\n  email: \"ses\",\n  marketplace: \"aws-marketplace\",\n  mobile: \"AWSMobileHubService\",\n  pinpoint: \"mobiletargeting\",\n  queue: \"sqs\",\n  \"git-codecommit\": \"codecommit\",\n  \"mturk-requester-sandbox\": \"mturk-requester\",\n  \"personalize-runtime\": \"personalize\"\n};\nvar UNSIGNABLE_HEADERS = \/* @__PURE__ *\/ new Set(&#91;\n  \"authorization\",\n  \"content-type\",\n  \"content-length\",\n  \"user-agent\",\n  \"presigned-expires\",\n  \"expect\",\n  \"x-amzn-trace-id\",\n  \"range\",\n  \"connection\"\n]);\nvar AwsClient = class {\n  constructor({ accesskeyID, secretAccessKey, sessionToken, service, region, cache, retries, initRetryMs }) {\n    if (accesskeyID == null)\n      throw new TypeError(\"accesskeyID is a required option\");\n    if (secretAccessKey == null)\n      throw new TypeError(\"secretAccessKey is a required option\");\n    this.accesskeyID = accesskeyID;\n    this.secretAccessKey = secretAccessKey;\n    this.sessionToken = sessionToken;\n    this.service = service;\n    this.region = region;\n    this.cache = cache || \/* @__PURE__ *\/ new Map();\n    this.retries = retries != null ? retries : 10;\n    this.initRetryMs = initRetryMs || 50;\n  }\n  async sign(input, init) {\n    if (input instanceof Request) {\n      const { method, url, headers, body } = input;\n      init = Object.assign({ method, url, headers }, init);\n      if (init.body == null &amp;&amp; headers.has(\"Content-Type\")) {\n        init.body = body != null &amp;&amp; headers.has(\"X-Amz-Content-Sha256\") ? body : await input.clone().arrayBuffer();\n      }\n      input = url;\n    }\n    const signer = new AwsV4Signer(Object.assign({ url: input }, init, this, init &amp;&amp; init.aws));\n    const signed = Object.assign({}, init, await signer.sign());\n    delete signed.aws;\n    try {\n      return new Request(signed.url.toString(), signed);\n    } catch (e) {\n      if (e instanceof TypeError) {\n        return new Request(signed.url.toString(), Object.assign({ duplex: \"half\" }, signed));\n      }\n      throw e;\n    }\n  }\n  async fetch(input, init) {\n    for (let i = 0; i &lt;= this.retries; i++) {\n      const fetched = fetch(await this.sign(input, init));\n      if (i === this.retries) {\n        return fetched;\n      }\n      const res = await fetched;\n      if (res.status &lt; 500 &amp;&amp; res.status !== 429) {\n        return res;\n      }\n      await new Promise((resolve) => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i)));\n    }\n    throw new Error(\"An unknown error occurred, ensure retries is not negative\");\n  }\n};\nvar AwsV4Signer = class {\n  constructor({ method, url, headers, body, accesskeyID, secretAccessKey, sessionToken, service, region, cache, datetime, signQuery, appendSessionToken, allHeaders, singleEncode }) {\n    if (url == null)\n      throw new TypeError(\"url is a required option\");\n    if (accesskeyID == null)\n      throw new TypeError(\"accesskeyID is a required option\");\n    if (secretAccessKey == null)\n      throw new TypeError(\"secretAccessKey is a required option\");\n    this.method = method || (body ? \"POST\" : \"GET\");\n    this.url = new URL(url);\n    this.headers = new Headers(headers || {});\n    this.body = body;\n    this.accesskeyID = accesskeyID;\n    this.secretAccessKey = secretAccessKey;\n    this.sessionToken = sessionToken;\n    let guessedService, guessedRegion;\n    if (!service || !region) {\n      &#91;guessedService, guessedRegion] = guessServiceRegion(this.url, this.headers);\n    }\n    this.service = service || guessedService || \"\";\n    this.region = region || guessedRegion || \"us-east-1\";\n    this.cache = cache || \/* @__PURE__ *\/ new Map();\n    this.datetime = datetime || (\/* @__PURE__ *\/ new Date()).toISOString().replace(\/&#91;:-]|\\.\\d{3}\/g, \"\");\n    this.signQuery = signQuery;\n    this.appendSessionToken = appendSessionToken || this.service === \"iotdevicegateway\";\n    this.headers.delete(\"Host\");\n    if (this.service === \"s3\" &amp;&amp; !this.signQuery &amp;&amp; !this.headers.has(\"X-Amz-Content-Sha256\")) {\n      this.headers.set(\"X-Amz-Content-Sha256\", \"UNSIGNED-PAYLOAD\");\n    }\n    const params = this.signQuery ? this.url.searchParams : this.headers;\n    params.set(\"X-Amz-Date\", this.datetime);\n    if (this.sessionToken &amp;&amp; !this.appendSessionToken) {\n      params.set(\"X-Amz-Security-Token\", this.sessionToken);\n    }\n    this.signableHeaders = &#91;\"host\", ...this.headers.keys()].filter((header) => allHeaders || !UNSIGNABLE_HEADERS.has(header)).sort();\n    this.signedHeaders = this.signableHeaders.join(\";\");\n    this.canonicalHeaders = this.signableHeaders.map((header) => header + \":\" + (header === \"host\" ? this.url.host : (this.headers.get(header) || \"\").replace(\/\\s+\/g, \" \"))).join(\"\\n\");\n    this.credentialString = &#91;this.datetime.slice(0, 8), this.region, this.service, \"aws4_request\"].join(\"\/\");\n    if (this.signQuery) {\n      if (this.service === \"s3\" &amp;&amp; !params.has(\"X-Amz-Expires\")) {\n        params.set(\"X-Amz-Expires\", \"86400\");\n      }\n      params.set(\"X-Amz-Algorithm\", \"AWS4-HMAC-SHA256\");\n      params.set(\"X-Amz-Credential\", this.accesskeyID + \"\/\" + this.credentialString);\n      params.set(\"X-Amz-SignedHeaders\", this.signedHeaders);\n    }\n    if (this.service === \"s3\") {\n      try {\n        this.encodedPath = decodeURIComponent(this.url.pathname.replace(\/\\+\/g, \" \"));\n      } catch (e) {\n        this.encodedPath = this.url.pathname;\n      }\n    } else {\n      this.encodedPath = this.url.pathname.replace(\/\\\/+\/g, \"\/\");\n    }\n    if (!singleEncode) {\n      this.encodedPath = encodeURIComponent(this.encodedPath).replace(\/%2F\/g, \"\/\");\n    }\n    this.encodedPath = encodeRfc3986(this.encodedPath);\n    const seenKeys = \/* @__PURE__ *\/ new Set();\n    this.encodedSearch = &#91;...this.url.searchParams].filter((&#91;k]) => {\n      if (!k)\n        return false;\n      if (this.service === \"s3\") {\n        if (seenKeys.has(k))\n          return false;\n        seenKeys.add(k);\n      }\n      return true;\n    }).map((pair) => pair.map((p) => encodeRfc3986(encodeURIComponent(p)))).sort((&#91;k1, v1], &#91;k2, v2]) => k1 &lt; k2 ? -1 : k1 > k2 ? 1 : v1 &lt; v2 ? -1 : v1 > v2 ? 1 : 0).map((pair) => pair.join(\"=\")).join(\"&amp;\");\n  }\n  async sign() {\n    if (this.signQuery) {\n      this.url.searchParams.set(\"X-Amz-Signature\", await this.signature());\n      if (this.sessionToken &amp;&amp; this.appendSessionToken) {\n        this.url.searchParams.set(\"X-Amz-Security-Token\", this.sessionToken);\n      }\n    } else {\n      this.headers.set(\"Authorization\", await this.authHeader());\n    }\n    return {\n      method: this.method,\n      url: this.url,\n      headers: this.headers,\n      body: this.body\n    };\n  }\n  async authHeader() {\n    return &#91;\n      \"AWS4-HMAC-SHA256 Credential=\" + this.accesskeyID + \"\/\" + this.credentialString,\n      \"SignedHeaders=\" + this.signedHeaders,\n      \"Signature=\" + await this.signature()\n    ].join(\", \");\n  }\n  async signature() {\n    const date = this.datetime.slice(0, 8);\n    const cacheKey = &#91;this.secretAccessKey, date, this.region, this.service].join();\n    let kCredentials = this.cache.get(cacheKey);\n    if (!kCredentials) {\n      const kDate = await hmac(\"AWS4\" + this.secretAccessKey, date);\n      const kRegion = await hmac(kDate, this.region);\n      const kService = await hmac(kRegion, this.service);\n      kCredentials = await hmac(kService, \"aws4_request\");\n      this.cache.set(cacheKey, kCredentials);\n    }\n    return buf2hex(await hmac(kCredentials, await this.stringToSign()));\n  }\n  async stringToSign() {\n    return &#91;\n      \"AWS4-HMAC-SHA256\",\n      this.datetime,\n      this.credentialString,\n      buf2hex(await hash(await this.canonicalString()))\n    ].join(\"\\n\");\n  }\n  async canonicalString() {\n    return &#91;\n      this.method.toUpperCase(),\n      this.encodedPath,\n      this.encodedSearch,\n      this.canonicalHeaders + \"\\n\",\n      this.signedHeaders,\n      await this.hexBodyHash()\n    ].join(\"\\n\");\n  }\n  async hexBodyHash() {\n    let hashHeader = this.headers.get(\"X-Amz-Content-Sha256\") || (this.service === \"s3\" &amp;&amp; this.signQuery ? \"UNSIGNED-PAYLOAD\" : null);\n    if (hashHeader == null) {\n      if (this.body &amp;&amp; typeof this.body !== \"string\" &amp;&amp; !(\"byteLength\" in this.body)) {\n        throw new Error(\"body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header\");\n      }\n      hashHeader = buf2hex(await hash(this.body || \"\"));\n    }\n    return hashHeader;\n  }\n};\nasync function hmac(key, string) {\n  const cryptoKey = await crypto.subtle.importKey(\n    \"raw\",\n    typeof key === \"string\" ? encoder.encode(key) : key,\n    { name: \"HMAC\", hash: { name: \"SHA-256\" } },\n    false,\n    &#91;\"sign\"]\n  );\n  return crypto.subtle.sign(\"HMAC\", cryptoKey, encoder.encode(string));\n}\nasync function hash(content) {\n  return crypto.subtle.digest(\"SHA-256\", typeof content === \"string\" ? encoder.encode(content) : content);\n}\nfunction buf2hex(buffer) {\n  return Array.prototype.map.call(new Uint8Array(buffer), (x) => (\"0\" + x.toString(16)).slice(-2)).join(\"\");\n}\nfunction encodeRfc3986(urlEncodedStr) {\n  return urlEncodedStr.replace(\/&#91;!'()*]\/g, (c) => \"%\" + c.charCodeAt(0).toString(16).toUpperCase());\n}\nfunction guessServiceRegion(url, headers) {\n  const { hostname, pathname } = url;\n  if (hostname.endsWith(\".r2.cloudflarestorage.com\")) {\n    return &#91;\"s3\", \"auto\"];\n  }\n  if (hostname.endsWith(\".backblazeb2.com\")) {\n    const match2 = hostname.match(\/^(?:&#91;^.]+\\.)?s3\\.(&#91;^.]+)\\.backblazeb2\\.com$\/);\n    return match2 != null ? &#91;\"s3\", match2&#91;1]] : &#91;\"\", \"\"];\n  }\n  const match = hostname.replace(\"dualstack.\", \"\").match(\/(&#91;^.]+)\\.(?:(&#91;^.]*)\\.)?amazonaws\\.com(?:\\.cn)?$\/);\n  let &#91;service, region] = (match || &#91;\"\", \"\"]).slice(1, 3);\n  if (region === \"us-gov\") {\n    region = \"us-gov-west-1\";\n  } else if (region === \"s3\" || region === \"s3-accelerate\") {\n    region = \"us-east-1\";\n    service = \"s3\";\n  } else if (service === \"iot\") {\n    if (hostname.startsWith(\"iot.\")) {\n      service = \"execute-api\";\n    } else if (hostname.startsWith(\"data.jobs.iot.\")) {\n      service = \"iot-jobs-data\";\n    } else {\n      service = pathname === \"\/mqtt\" ? \"iotdevicegateway\" : \"iotdata\";\n    }\n  } else if (service === \"autoscaling\") {\n    const targetPrefix = (headers.get(\"X-Amz-Target\") || \"\").split(\".\")&#91;0];\n    if (targetPrefix === \"AnyScaleFrontendService\") {\n      service = \"application-autoscaling\";\n    } else if (targetPrefix === \"AnyScaleScalingPlannerFrontendService\") {\n      service = \"autoscaling-plans\";\n    }\n  } else if (region == null &amp;&amp; service.startsWith(\"s3-\")) {\n    region = service.slice(3).replace(\/^fips-|^external-1\/, \"\");\n    service = \"s3\";\n  } else if (service.endsWith(\"-fips\")) {\n    service = service.slice(0, -5);\n  } else if (region &amp;&amp; \/-\\d$\/.test(service) &amp;&amp; !\/-\\d$\/.test(region)) {\n    &#91;service, region] = &#91;region, service];\n  }\n  return &#91;HOST_SERVICES&#91;service] || service, region];\n}\n\n\/\/ index.js\nvar UNSIGNABLE_HEADERS2 = &#91;\n  \/\/ These headers appear in the request, but are not passed upstream\n  \"x-forwarded-proto\",\n  \"x-real-ip\",\n  \/\/ We can't include accept-encoding in the signature because Cloudflare\n  \/\/ sets the incoming accept-encoding header to \"gzip, br\", then modifies\n  \/\/ the outgoing request to set accept-encoding to \"gzip\".\n  \/\/ Not cool, Cloudflare!\n  \"accept-encoding\"\n];\nvar HTTPS_PROTOCOL = \"https:\";\nvar HTTPS_PORT = \"443\";\nvar RANGE_RETRY_ATTEMPTS = 3;\nfunction filterHeaders(headers, env) {\n  return new Headers(Array.from(headers.entries()).filter(\n    (pair) => !UNSIGNABLE_HEADERS2.includes(pair&#91;0]) &amp;&amp; !pair&#91;0].startsWith(\"cf-\") &amp;&amp; !(\"ALLOWED_HEADERS\" in env &amp;&amp; !env.ALLOWED_HEADERS.includes(pair&#91;0]))\n  ));\n}\nvar my_proxy_default = {\n  async fetch(request, env) {\n    if (!&#91;\"GET\", \"HEAD\"].includes(request.method)) {\n      return new Response(null, {\n        status: 405,\n        statusText: \"Method Not Allowed\"\n      });\n    }\n    const url = new URL(request.url);\n    url.protocol = HTTPS_PROTOCOL;\n    url.port = HTTPS_PORT;\n    let path = url.pathname.replace(\/^\\\/\/, \"\");\n    path = path.replace(\/\\\/$\/, \"\");\n    const pathSegments = path.split(\"\/\");\n    if (env.ALLOW_LIST_BUCKET !== \"true\") {\n      if (env.BUCKET_NAME === \"$path\" &amp;&amp; pathSegments.length &lt; 2 || env.BUCKET_NAME !== \"$path\" &amp;&amp; path.length === 0) {\n        return new Response(null, {\n          status: 404,\n          statusText: \"Not Found\"\n        });\n      }\n    }\n    switch (env.BUCKET_NAME) {\n      case \"$path\":\n        url.hostname = env.B2_ENDPOINT;\n        break;\n      case \"$host\":\n        url.hostname = url.hostname.split(\".\")&#91;0] + \".\" + env.B2_ENDPOINT;\n        break;\n      default:\n        url.hostname = env.BUCKET_NAME + \".\" + env.B2_ENDPOINT;\n        break;\n    }\n    const headers = filterHeaders(request.headers, env);\n    const endpointRegex = \/^s3\\.(&#91;a-zA-Z0-9-]+)\\.backblazeb2\\.com$\/;\n    const &#91;, aws_region] = env.B2_ENDPOINT.match(endpointRegex);\n    const client = new AwsClient({\n      \"accesskeyID\": env.B2_APPLICATION_KEY_ID,\n      \"secretAccessKey\": env.B2_APPLICATION_KEY,\n      \"service\": \"s3\",\n      \"region\": aws_region\n    });\n    const signedRequest = await client.sign(url.toString(), {\n      method: request.method,\n      headers\n    });\n    if (signedRequest.headers.has(\"range\")) {\n      let attempts = RANGE_RETRY_ATTEMPTS;\n      let response;\n      do {\n        let controller = new AbortController();\n        response = await fetch(signedRequest.url, {\n          method: signedRequest.method,\n          headers: signedRequest.headers,\n          signal: controller.signal\n        });\n        if (response.headers.has(\"content-range\")) {\n          if (attempts &lt; RANGE_RETRY_ATTEMPTS) {\n            console.log(`Retry for ${signedRequest.url} succeeded - response has content-range header`);\n          }\n          break;\n        } else if (response.ok) {\n          attempts -= 1;\n          console.error(`Range header in request for ${signedRequest.url} but no content-range header in response. Will retry ${attempts} more times`);\n          if (attempts > 0) {\n            controller.abort();\n          }\n        } else {\n          break;\n        }\n      } while (attempts > 0);\n      if (attempts &lt;= 0) {\n        console.error(`Tried range request for ${signedRequest.url} ${RANGE_RETRY_ATTEMPTS} times, but no content-range in response.`);\n      }\n      return response;\n    }\n    return fetch(signedRequest);\n  }\n};\nexport {\n  my_proxy_default as default\n};\n\/*! Bundled license information:\n\naws4fetch\/dist\/aws4fetch.esm.mjs:\n  (**\n   * @license MIT &lt;https:\/\/opensource.org\/licenses\/MIT>\n   * @copyright Michael Hart 2022\n   *)\n*\/\n\/\/# sourceMappingURL=index.js.map<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u70b9\u51fb&nbsp;<kbd>\u4fdd\u5b58\u5e76\u90e8\u7f72<\/kbd>&nbsp;\u6309\u94ae\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u56db\u914d\u7f6e-cloudflare-worker\">\u56db\u3001\u914d\u7f6e Cloudflare Worker<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd4\u56de\u65b0\u521b\u5efa\u7684 Worker \u9875\u9762\uff0c\u70b9\u51fb\u4e0a\u65b9&nbsp;<em>\u8bbe\u7f6e<\/em>&nbsp;\u9009\u9879\u5361\uff0c\u518d\u70b9\u51fb\u5de6\u4fa7&nbsp;<em>\u53d8\u91cf<\/em>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb\u00a0<kbd>\u6dfb\u52a0\u53d8\u91cf<\/kbd>\u00a0\u6309\u94ae\uff0c\u4f9d\u6b21\u6dfb\u52a0 5 \u4e2a\u53d8\u91cf\uff0c\u53d8\u91cf\u540d\u79f0 \u548c \u503c \u5206\u522b\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALLOW_LIST_BUCKET = false\nB2_APPLICATION_KEY = \u7b2c\u4e8c\u6b65\u4fdd\u5b58\u7684 applicationKey\nB2_APPLICATION_KEY_ID = \u7b2c\u4e8c\u6b65\u4fdd\u5b58\u7684 keyID\nB2_ENDPOINT = \u7b2c\u4e00\u6b65\u8bb0\u4e0b\u7684 Endpoint \u503c\uff08\u5982 s3.us-west-004.backblazeb2.com\uff09\nBUCKET_NAME = \u79c1\u5bc6\u6876\u540d\uff08\u5982 it-is-just-a-test-bucket\uff09<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6dfb\u52a0\u5b8c\u540e\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"461\" src=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/14.png\" alt=\"\" class=\"wp-image-251\" srcset=\"https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/14.png 748w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/14-300x185.png 300w, https:\/\/freevipus.nyc.mn\/wp-content\/uploads\/2024\/09\/14-150x92.png 150w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u5b89\u5168\u8d77\u89c1\uff0c\u8f93\u5165\u5b8c B2_APPLICATION_KEY \u7684\u503c\u540e\uff0c\u70b9\u51fb\u53f3\u4fa7\u7684\u00a0<kbd>\u52a0\u5bc6<\/kbd>\u00a0\u6309\u94ae\uff0c\u4f1a\u663e\u793a\u00a0<em>\u6b64\u503c\u5728\u4fdd\u5b58\u540e\u65e0\u6cd5\u518d\u8fdb\u884c\u67e5\u770b<\/em>\u00a0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb\u00a0<kbd>\u4fdd\u5b58\u5e76\u90e8\u7f72<\/kbd>\u00a0\u6309\u94ae\uff0c\u5b8c\u6210\u90e8\u7f72\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e94\u81ea\u5b9a\u4e49\u57df\u540d\">\u4e94\u3001\u81ea\u5b9a\u4e49\u57df\u540d<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb\u5de6\u4fa7&nbsp;<em>\u89e6\u53d1\u5668<\/em>&nbsp;\uff0c\u7136\u540e\u70b9\u51fb&nbsp;<kbd>\u6dfb\u52a0\u81ea\u5b9a\u4e49\u57df<\/kbd>&nbsp;\u6309\u94ae\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u914d\u7f6e Backblaze B2 \u79c1\u5bc6\u6876<a href=\"https:\/\/blog.standat42.com\/posts\/image-hosting-backblaze-b2-private-cloudflare-workers-picgo\/#%E5%85%AD%E9%85%8D%E7%BD%AE-backblaze-b2-%E7%A7%81%E5%AF%86%E6%A1%B6\">#<\/a><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u56de\u5230 Backblaze \uff0c\u5b9a\u4f4d\u5230\u65b0\u5efa\u7684\u79c1\u5bc6\u6876\uff0c\u70b9\u51fb\u00a0<em>Bucket Settings<\/em>\u00a0\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u00a0<em>Bucket Info<\/em>\u00a0\u9879\u586b\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"Cache-Control\": \"public, max-age=86400\"} <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u63d0\u793a\uff1a86400 \u8868\u793a\u7f13\u5b58\u4e00\u5929\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u66f4\u5927\u3002<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u70b9\u51fb\u00a0<kbd>Update Bucket<\/kbd>\u00a0\u6309\u94ae\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e03\u8bbf\u95ee\u6d4b\u8bd5\">\u4e03\u3001\u8bbf\u95ee\u6d4b\u8bd5<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e0a\u4f20\u56fe\u7247\u5230\u79c1\u5bc6\u6876<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9a\u4f4d\u5230\u65b0\u5efa\u7684\u79c1\u5bc6\u6876\uff0c\u70b9\u51fb&nbsp;<kbd>Upload\/Download<\/kbd>&nbsp;\u6309\u94ae\uff0c\u7136\u540e\u7ee7\u7eed\u70b9\u51fb&nbsp;<kbd>Upload<\/kbd>&nbsp;\u6309\u94ae\uff0c\u4e0a\u4f20\u4e00\u4e2a\u56fe\u7247\uff08\u5982 test-image.jpg\uff09\u3002<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u8bbf\u95ee\u6d4b\u8bd5<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u76f4\u63a5\u8bbf\u95ee S3 URL (https:\/\/it-is-just-a-test-bucket.s3.us-west-004.backblazeb2.com\/test-image.jpg) \u662f\u770b\u4e0d\u5230\u56fe\u7247\u7684\u3002<img decoding=\"async\" src=\"https:\/\/blogimg.standat42.com\/20240323-imagehosting-303.png\" alt=\"\u672a\u6388\u6743\u8bbf\u95ee\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbf\u95ee\u81ea\u5b9a\u4e49\u57df\u540d\u7684 URl (https:\/\/test.standat42.com\/test-image.jpg) \u5219\u53ef\u4ee5\u770b\u5230\u56fe\u7247\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73b0\u5728 Backblaze \u521b\u5efa\u6876\u7684\u7b56\u7565\u53d1\u751f\u4e86\u53d8\u5316\uff1a\u5fc5\u987b\u652f\u4ed8\u4e00\u6b21\u6027\u7684\u8d39\u7528\uff081 \u7f8e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-6"],"_links":{"self":[{"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=244"}],"version-history":[{"count":1,"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions\/252"}],"wp:attachment":[{"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freevipus.nyc.mn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}