[{"data":1,"prerenderedAt":331},["ShallowReactive",2],{"content:\u002F2026\u002Fsanyue-imgbed-random":3,"surround:\u002F2026\u002Fsanyue-imgbed-random":325},{"id":4,"title":5,"body":6,"categories":293,"date":295,"description":296,"draft":297,"extension":298,"image":299,"meta":300,"navigation":304,"path":305,"permalink":306,"published":306,"readingTime":307,"recommend":306,"references":306,"seo":312,"sitemap":313,"stem":316,"tags":317,"type":322,"updated":323,"__hash__":324},"content\u002Fposts\u002F2026\u002Fsanyue-imgbed-random.md","三月图床随机图 API 排障记录：403 Directory not allowed",{"type":7,"value":8,"toc":282},"minimark",[9,63,67,74,78,86,90,98,101,106,113,121,135,141,147,150,153,274,277],[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",[64,151,152],{"id":152},"参数速查",[154,155,156,172],"table",{},[157,158,159],"thead",{},[160,161,162,166,169],"tr",{},[163,164,165],"th",{},"参数",[163,167,168],{},"默认",[163,170,171],{},"说明",[173,174,175,192,210,232,250],"tbody",{},[160,176,177,182,185],{},[178,179,180],"td",{},[34,181,133],{"code":133},[178,183,184],{},"—",[178,186,187,188,191],{},"直接返回图片字节，此时 ",[34,189,190],{"code":190},"form"," 失效",[160,193,194,199,201],{},[178,195,196],{},[34,197,198],{"code":198},"form=text",[178,200,44],{},[178,202,203,204,206,207],{},"设为 ",[34,205,118],{"code":118}," 返回纯路径；否则返回 ",[34,208,209],{"code":209},"{\"url\":\"\u002Ffile\u002Fxx\u002Fyy.webp\"}",[160,211,212,216,218],{},[178,213,214],{},[34,215,129],{"code":129},[178,217,184],{},[178,219,220,221,224,225,228,229],{},"目录前缀，相对路径（写成 ",[34,222,223],{"code":223},"\u002Fwp"," 或 ",[34,226,227],{"code":227},"wp"," 都对）；",[55,230,231],{},"白名单非空时必填",[160,233,234,239,244],{},[178,235,236],{},[34,237,238],{"code":238},"content",[178,240,241],{},[34,242,243],{"code":243},"image",[178,245,246,249],{},[34,247,248],{"code":248},"image,video","，逗号分隔",[160,251,252,257,259],{},[178,253,254],{},[34,255,256],{"code":256},"orientation",[178,258,184],{},[178,260,261,264,265,264,268,264,271],{},[34,262,263],{"code":263},"landscape"," \u002F ",[34,266,267],{"code":267},"portrait",[34,269,270],{"code":270},"square",[34,272,273],{"code":273},"auto",[64,275,276],{"id":276},"完",[278,279],"img",{"src":280,"alt":281},"https:\u002F\u002Fimg.kr-zhan.top\u002Frandom?type=img&dir=\u002Fsj","一张横向随机图片，来自 sj 图片集合并作为网页背景展示；画面及其中的主体会随接口请求而变化",{"title":45,"searchDepth":283,"depth":283,"links":284},4,[285,291,292],{"id":66,"depth":286,"text":66,"children":287},2,[288,290],{"id":77,"depth":289,"text":77},3,{"id":88,"depth":289,"text":89},{"id":152,"depth":286,"text":152},{"id":276,"depth":286,"text":276},[294],"技术","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":301,"slots":303},[302],"toc",{},true,"\u002F2026\u002Fsanyue-imgbed-random",null,{"text":308,"minutes":309,"time":310,"words":311},"2 min read",1.505,90300,301,{"title":5,"description":296},{"loc":305,"images":314},[315],{"loc":280},"posts\u002F2026\u002Fsanyue-imgbed-random",[318,319,320,321],"CloudFlare-ImgBed","图床","Cloudflare","排障","tech","2026-11-28 18:49:00","mZmWIhwhusHuzHYZNvZDwCNecMMdhcT0504UWxY7-hU",[326,306],{"title":327,"path":328,"stem":329,"date":330,"type":322,"children":-1},"Git用法简记","\u002F2026\u002Fgit-notes","posts\u002F2026\u002Fgit-notes","2026-10-04 00:25:00",1795924258410]