{"id":68723,"date":"2020-04-19T18:04:55","date_gmt":"2020-04-19T10:04:55","guid":{"rendered":"http:\/\/4563.org\/?p=68723"},"modified":"2020-04-19T18:04:55","modified_gmt":"2020-04-19T10:04:55","slug":"%e3%80%90%e5%bc%80%e6%ba%90%e3%80%91%e5%9c%a8-cf-workers-%e6%90%ad%e5%bb%ba%e8%87%aa%e5%b7%b1%e7%9a%84-t-cn-%e7%9f%ad%e7%bd%91%e5%9d%80%e5%85%a5%e5%8f%a3","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=68723","title":{"rendered":"\u3010\u5f00\u6e90\u3011\u5728 CF Workers \u642d\u5efa\u81ea\u5df1\u7684 t.cn \u77ed\u7f51\u5740\u5165\u53e3"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>Mr.<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u3010\u5f00\u6e90\u3011\u5728 CF Workers \u642d\u5efa\u81ea\u5df1\u7684 t.cn \u77ed\u7f51\u5740\u5165\u53e3<\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 Mr. \u4e8e 2020-4-19 18:04 \u7f16\u8f91 <\/p>\n<p> \u4ece @ljm4216 \u5927\u4f6c\u7684\u5e16\u5b50 https:\/\/www.hostloc.com\/thread-676833-1-1.html \u5f97\u5230\u542f\u53d1\uff0c<br \/>  \u624d\u77e5\u9053\u539f\u6765 t.cn \u7684\u63a5\u53e3\u8fd9\u4e48\u7b80\u5355\uff0c\u4e8e\u662f\u64b8\u4e86\u4e2a\u57fa\u4e8e Cloudflare Workers \u7684\u5728\u7ebf\u7248\u9875\u9762\u3002<\/p>\n<p>  \u6f14\u793a\u5730\u5740\uff1ahttp:\/\/t.cn\/A6wl4Dqs<\/p>\n<p>  \u98df\u7528\u65b9\u6cd5\uff1a\u521b\u5efa\u4e2a workers \u628a\u4ee5\u4e0b\u4ee3\u7801\u7c98\u8d34\u8fdb\u53bb\u5c31\u53ef\u4ee5\u4e86\uff0c\u5feb\u628a\u4eca\u5929\u64b8\u7684\u514d\u8d39\u57df\u540d\u7528\u8d77\u6765\u5427\uff01<\/p>\n<p>  addEventListener(&#8216;fetch&#8217;, (event) =&gt; {<br \/>  return event.respondWith(handleRequest(event.request));<br \/>  })<\/p>\n<p>  const handleRequest = async (request) =&gt; {<br \/>  const render = (body) =&gt; {<br \/>  &nbsp; &nbsp; return new Response(`<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;!doctype html&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;html&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;head&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;meta charset=&quot;utf-8&quot; \/&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,initial-scale=1&quot; \/&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;title&gt;T.CN \u77ed\u7f51\u5740&lt;\/title&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;\/head&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;body&gt;${body}&lt;\/body&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;\/html&gt;`.trim(), {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;status: 200,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;headers: {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;Content-Type&#8217;: &#8216;text\/html; charset=utf-8&#8217;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp; });<br \/>  }<br \/>  request = new URL(request.url);<br \/>  if (request.pathname !== &#8216;\/&#8217;) return new Response(null, { status: 404 });<br \/>  if (request.searchParams.has(&#8216;url&#8217;)) {<br \/>  &nbsp; &nbsp; const url = request.searchParams.get(&#8216;url&#8217;);<br \/>  &nbsp; &nbsp; const response = await fetch(`http:\/\/service.weibo.com\/share\/share.php?url=${encodeURIComponent(url)}&amp;title=1`);<br \/>  &nbsp; &nbsp; const html = await response.text();<br \/>  &nbsp; &nbsp; const short = html.match(\/http:\/\/t.cn\/w+\/i);<br \/>  &nbsp; &nbsp; const refer = html.match(\/$refers+: &quot;(.+?)&quot;\/i);<br \/>  &nbsp; &nbsp; if (short &amp;&amp; refer) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;return render(`<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;\u7f29\u77ed\u7ed3\u679c\uff1a&lt;a href=&quot;${short}&quot;&gt;${short}&lt;\/a&gt;&lt;br \/&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;\u539f\u59cb\u7f51\u5740\uff1a&lt;a href=&quot;${refer}&quot;&gt;${refer}&lt;\/a&gt;&lt;br \/&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&lt;a href=&quot;\/&quot;&gt;\u8fd4\u56de&lt;\/a&gt;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;`);<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; return render(`\u8bf7\u6c42\u5931\u8d25`);<br \/>  }<br \/>  return render(`<br \/>  &nbsp; &nbsp; &lt;form method=&quot;GET&quot;&gt;<br \/>  &nbsp; &nbsp; &lt;input name=&quot;url&quot; placeholder=&quot;URL&quot; \/&gt;<br \/>  &nbsp; &nbsp; &lt;button type=&quot;submit&quot;&gt;\u538b\u7f29&lt;\/button&gt;<br \/>  &nbsp; &nbsp; &lt;\/form&gt;<br \/>  `);<br \/>  }\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>future<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u652f\u6301\u5927\u4f6c\uff01\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>robot<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u597d\u4e1c\u4e1c\u3002\u7d2b\u85af\u8865\u4e01\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>Reves<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u611f\u8c22\u5206\u4eab\uff0c\u4e00\u4f1a\u513f\u8bd5\u8bd5\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u55f7\u55f7<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u725b\u6279\u725b\u6279\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>tssz<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u6536\u85cf\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>shenke<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\thttps:\/\/blog.csdn.net\/sculpta\/article\/details\/104142531\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>Mr.<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tshenke \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-4-19 18:12<br \/>  https:\/\/blog.csdn.net\/sculpta\/article\/details\/104142531<\/p>\n<p> \u4f60\u6015\u662f\u7406\u89e3\u9519\u4e86\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>qytang<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u725b\u903c\uff01\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mr. \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u3010\u5f00\u6e90\u3011\u5728&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/68723"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=68723"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/68723\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=68723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=68723"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=68723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}