[{"data":1,"prerenderedAt":201},["ShallowReactive",2],{"content:\u002F2026\u002Fsanyue-imgbed-random":3,"surround:\u002F2026\u002Fsanyue-imgbed-random":195},{"id":4,"title":5,"body":6,"categories":165,"date":167,"description":168,"draft":169,"extension":170,"image":171,"meta":172,"navigation":176,"path":177,"permalink":178,"published":178,"readingTime":179,"recommend":178,"references":178,"seo":184,"sitemap":185,"stem":186,"tags":187,"type":192,"updated":193,"__hash__":194},"content\u002Fposts\u002F2026\u002Fsanyue-imgbed-random.md","随机图 API 排障记录：403 Directory not allowed",{"type":7,"value":8,"toc":156},"minimark",[9,63,67,74,78,86,90,98,101,106,113,121,135,141,147,150],[10,11,12,16,27,30,38,48,51],"timeline",{},[13,14,15],"p",{},"{背景}",[13,17,18,19,26],{},"自建的 ",[20,21,25],"a",{"href":22,"rel":23},"https:\u002F\u002Fgithub.com\u002FMarSeventh\u002FCloudFlare-ImgBed",[24],"nofollow","CloudFlare ImgBed"," 一直当图床用，最近想把它的随机图接口接过来，做站点图床。",[13,28,29],{},"{现象}",[13,31,32,33,37],{},"接口开了，参数也照文档填了，但 ",[34,35,36],"code",{"code":36},"\u002Frandom"," 一律回\"Directory not allowed\"：",[39,40,46],"pre",{"className":41,"code":43,"language":44,"meta":45},[42],"language-json","{\"error\":\"Directory not allowed\"}\n","json","",[34,47,43],{"__ignoreMap":45},[13,49,50],{},"{结果}",[13,52,53,54,58,59,62],{},"白名单里填的是",[55,56,57],"strong",{},"接口路由","而不是",[55,60,61],{},"存储目录","，当白名单非空时，请求必须带 dir",[64,65,66],"h2",{"id":66},"先分清两个域名",[13,68,69,70,73],{},"官方随机接口文档链接 ",[34,71,72],{"code":72},"https:\u002F\u002Fcfbed.sanyue.de\u002Fapi\u002Frandom.html","，其中写的接口是这样的",[75,76,77],"h3",{"id":77},"网站随机背景",[39,79,84],{"className":80,"code":82,"language":83,"meta":45},[81],"language-html","\u003Cimg src=\"https:\u002F\u002Fyour.domain\u002Frandom?type=img&orientation=landscape\" alt=\"随机背景\">\n","html",[34,85,82],{"__ignoreMap":45},[75,87,89],{"id":88},"css-背景图","CSS 背景图",[39,91,96],{"className":92,"code":94,"language":95,"meta":45},[93],"language-css",".hero {\n  background-image: url('https:\u002F\u002Fyour.domain\u002Frandom?type=img&orientation=landscape');\n  background-size: cover;\n}\n","css",[34,97,94],{"__ignoreMap":45},[13,99,100],{},"但是请求仍然返回",[39,102,104],{"className":103,"code":43,"language":44,"meta":45},[42],[34,105,43],{"__ignoreMap":45},[107,108,109],"ul",{},[110,111,112],"li",{},"当白名单非空时，请求必须带 dir  !!!",[39,114,119],{"className":115,"code":117,"language":118},[116],"language-text","\u002Frandom                  -> 403  Directory not allowed\n\u002Frandom?type=img         -> 403  Directory not allowed\n","text",[34,120,117],{"__ignoreMap":45},[13,122,123,124,130,131,134],{},"白名单不为空，",[55,125,126,127],{},"所有请求都得显式带上 ",[34,128,129],{"code":129},"dir","，包括最常用的 ",[34,132,133],{"code":133},"type=img"," 直出图片。随机图片请求都得带参数：",[39,136,139],{"className":137,"code":138,"language":83,"meta":45},[81],"\u003Cimg src=\"https:\u002F\u002Fimg.example.com\u002Frandom?type=img&dir=\u002Fwp\" alt=\"随机图\">\n",[34,140,138],{"__ignoreMap":45},[39,142,145],{"className":143,"code":144,"language":95,"meta":45},[93],".hero {\n  background-image: url('https:\u002F\u002Fimg.example.com\u002Frandom?type=img&dir=\u002Fwp&orientation=landscape')，'&dir=\u002Fwp'\n  background-size: cover;\n}\n",[34,146,144],{"__ignoreMap":45},[13,148,149],{},"HTTP\u002F2 404\ncontent-type: image\u002Fpng\ncontent-length: 418744\ncf-cache-status: HIT\nage: 6",[39,151,154],{"className":152,"code":153,"language":118},[116],"\n## 参数速查\n\n| 参数 | 默认 | 说明 |\n| --- | --- | --- |\n| `type=img` | — | 直接返回图片字节，此时 `form` 失效 |\n| `form=text` | json | 设为 `text` 返回纯路径；否则返回 `{\"url\":\"\u002Ffile\u002Fxx\u002Fyy.webp\"}` |\n| `dir` | — | 目录前缀，相对路径（写成 `\u002Fwp` 或 `wp` 都对）；**白名单非空时必填** |\n| `content` | `image` | `image,video`，逗号分隔 |\n| `orientation` | — | `landscape` \u002F `portrait` \u002F `square` \u002F `auto` |\n\n## 完\n\u003Cimg src=\"https:\u002F\u002Fimg.kr-zhan.top\u002Frandom?type=img&dir=\u002Fsj\" alt=\"一张横向随机图片，来自 sj 图片集合并作为网页背景展示；画面及其中的主体会随接口请求而变化\">\n",[34,155,153],{"__ignoreMap":45},{"title":45,"searchDepth":157,"depth":157,"links":158},4,[159],{"id":66,"depth":160,"text":66,"children":161},2,[162,164],{"id":77,"depth":163,"text":77},3,{"id":88,"depth":163,"text":89},[166],"技术","2026-11-28 18:00:00","CloudFlare ImgBed 随机图接口 \"error\":\"Directory not allowed\" 的排查过程",false,"md","https:\u002F\u002Fimg.kr-zhan.top\u002Ffile\u002Fwp\u002Fsanyue-img-post.webp",{"aside":173,"slots":175},[174],"toc",{},true,"\u002F2026\u002Fsanyue-imgbed-random",null,{"text":180,"minutes":181,"time":182,"words":183},"2 min read",1.88,112800,376,{"title":5,"description":168},{"loc":177},"posts\u002F2026\u002Fsanyue-imgbed-random",[188,189,190,191],"CloudFlare-ImgBed","图床","Cloudflare","排障","tech","2026-11-28 18:49:00","E98S28GRtGX8B7IveWwm2exMRFHVHCpre3dngt3YMTg",[196,178],{"title":197,"path":198,"stem":199,"date":200,"type":192,"children":-1},"Git用法简记","\u002F2026\u002Fgit-notes","posts\u002F2026\u002Fgit-notes","2026-10-04 00:25:00",1795864433629]