feat(api): 新增素材检索 API 服务(图标/海报检索 + SVG 直链 + Key 鉴权 + 中文语义检索)

This commit is contained in:
sgp
2026-11-04 16:42:02 +08:00
parent 9e222877ea
commit dce05d6516
15 changed files with 1848 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
[Unit]
Description=画个标素材 API
After=network.target
[Service]
Type=simple
User=ubuntu
Group=ubuntu
WorkingDirectory=/opt/drawlogo-api
ExecStart=/usr/bin/node --max-old-space-size=384 server.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production
# 限制内存,避免索引服务挤占同机其他项目
MemoryMax=900M
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ReadWritePaths=/opt/drawlogo-api
[Install]
WantedBy=multi-user.target
+13
View File
@@ -0,0 +1,13 @@
# 画个标素材 API —— 追加到 /etc/nginx/sites-enabled/drawlogo-zhuig-com.conf 的 443 server 块内
# 必须用 ^~:否则 /api/v1/icons/xxx.svg 会被下面的 \.svg$ 正则 location 截走 → 404
location ^~ /api/ {
proxy_pass http://127.0.0.1:7891;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 10s;
proxy_read_timeout 30s;
proxy_send_timeout 15s;
client_max_body_size 1m;
}
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
"""
把 /api/ 反代片段插入 drawlogo 站点的 **443 server 块**(幂等,可重复执行)
注意:不能用「第一个 location /」做锚点——那是 80 端口块。
这里改用 443 块独有的 access_log 行做锚点。
"""
import re
import sys
CONF = '/etc/nginx/sites-enabled/drawlogo-zhuig-com.conf'
SNIP = '/opt/drawlogo-api/deploy/nginx-location.conf'
ANCHOR = ' access_log /var/log/nginx/drawlogo_zhuig_access.log;'
text = open(CONF, encoding='utf-8').read()
# 1) 清理历史上放错位置的 /api/ 块(兼容 location /api/ 与 location ^~ /api/)
API_RE = re.compile(r'location\s+(?:\^~\s+)?/api/\s*\{')
while True:
m = API_RE.search(text)
if not m:
break
i = text.find('{', m.start())
depth = 0
end = -1
for j in range(i, len(text)):
if text[j] == '{':
depth += 1
elif text[j] == '}':
depth -= 1
if depth == 0:
end = j + 1
break
if end < 0:
print('ERROR: /api/ 块大括号不配对')
sys.exit(1)
text = text[:m.start()] + text[end:]
# 2) 插入到 443 块(锚点:该块独有的 access_log)
if ANCHOR not in text:
print('ERROR: 未找到 443 块的 access_log 锚点')
sys.exit(1)
snippet = open(SNIP, encoding='utf-8').read().rstrip() + '\n'
text = text.replace(ANCHOR, snippet + '\n' + ANCHOR, 1)
open(CONF, 'w', encoding='utf-8').write(text)
print('patched')