-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_komodo.sh
More file actions
executable file
·268 lines (229 loc) · 8.71 KB
/
Copy pathcheck_komodo.sh
File metadata and controls
executable file
·268 lines (229 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/sh
set -eu
if [ "$#" -lt 1 ]; then
echo "usage: $0 RUN_DIR" >&2
exit 1
fi
RUN_DIR="$1"
OUT_DIR="$RUN_DIR/api/komodo"
REPORT_DIR="$RUN_DIR/reports"
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname "$0")" && pwd)"
REPO_DIR="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)"
mkdir -p "$OUT_DIR" "$REPORT_DIR"
ERROR_FILE="$REPORT_DIR/komodo-errors.txt"
: > "$REPORT_DIR/komodo-product-modified.tsv"
: > "$REPORT_DIR/komodo-controller-sections.tsv"
: > "$REPORT_DIR/komodo-machine-sections.tsv"
: > "$REPORT_DIR/komodo-frame-sections.tsv"
: > "$REPORT_DIR/komodo-controller-media-interesting.tsv"
: > "$REPORT_DIR/komodo-machine-media.tsv"
: > "$REPORT_DIR/komodo-frame-media.tsv"
: > "$REPORT_DIR/komodo-visual-assets.tsv"
: > "$ERROR_FILE"
load_local_env() {
env_file="${KOMODO_ENV_FILE:-$REPO_DIR/.local/komodo-env.sh}"
if [ -f "$env_file" ]; then
# shellcheck disable=SC1090
. "$env_file"
fi
}
configure_playwright_runtime() {
NODE_BIN="${NODE_BIN:-}"
if [ -z "$NODE_BIN" ]; then
NODE_BIN="$(command -v node 2>/dev/null || true)"
fi
bundled_node="$HOME/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node"
if [ -z "$NODE_BIN" ] && [ -x "$bundled_node" ]; then
NODE_BIN="$bundled_node"
fi
export NODE_BIN
if [ -z "${NODE_PATH:-}" ]; then
for node_modules in \
"$REPO_DIR/node_modules" \
"$HOME/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules"
do
if [ -d "$node_modules" ]; then
NODE_PATH="$node_modules"
export NODE_PATH
break
fi
done
fi
}
cdp_endpoint_alive() {
endpoint="${PLAYWRIGHT_CDP_ENDPOINT:-}"
if [ -z "$endpoint" ]; then
return 1
fi
curl --max-time 2 -fsS "$endpoint/json/version" >/dev/null 2>&1
}
KOMODO_BOOTSTRAP_ATTEMPTED=0
bootstrap_dedicated_browser() {
if [ "${KOMODO_PLAYWRIGHT_FALLBACK:-0}" != "1" ] || [ "${KOMODO_AUTO_BOOTSTRAP:-1}" = "0" ]; then
return 0
fi
if [ "$KOMODO_BOOTSTRAP_ATTEMPTED" = "1" ]; then
return 0
fi
KOMODO_BOOTSTRAP_ATTEMPTED=1
bootstrap_cmd="${KOMODO_BOOTSTRAP_CMD:-$SCRIPT_DIR/bootstrap_komodo.sh}"
if [ ! -x "$bootstrap_cmd" ]; then
printf '%s\n' "Komodo bootstrap command not executable: $bootstrap_cmd" >> "$ERROR_FILE"
return 0
fi
if "$bootstrap_cmd" >/dev/null 2>>"$ERROR_FILE"; then
load_local_env
fi
}
maybe_set_cdp_endpoint() {
if [ -n "${PLAYWRIGHT_CDP_ENDPOINT:-}" ]; then
if cdp_endpoint_alive; then
return 0
fi
unset PLAYWRIGHT_CDP_ENDPOINT
fi
if [ -z "${PLAYWRIGHT_PROFILE_DIR:-}" ]; then
bootstrap_dedicated_browser
return 0
fi
port="$(ps aux | awk -v profile="$PLAYWRIGHT_PROFILE_DIR" '
index($0, profile) && match($0, /--remote-debugging-port=([0-9]+)/) {
value = substr($0, RSTART, RLENGTH)
sub(/^--remote-debugging-port=/, "", value)
print value
exit
}
' 2>/dev/null || true)"
if [ -n "$port" ]; then
PLAYWRIGHT_CDP_ENDPOINT="http://127.0.0.1:$port"
export PLAYWRIGHT_CDP_ENDPOINT
if cdp_endpoint_alive; then
return 0
fi
unset PLAYWRIGHT_CDP_ENDPOINT
fi
bootstrap_dedicated_browser
}
load_local_env
KOMODO_USER_AGENT="${KOMODO_USER_AGENT:-Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36}"
export KOMODO_USER_AGENT
fetch_json() {
name="$1"
url="$2"
allow_fallback="${3:-1}"
tmp="$OUT_DIR/$name.json.tmp"
if curl -A "$KOMODO_USER_AGENT" --retry 1 --retry-delay 1 --max-time 12 -fsSL "$url" > "$tmp" 2>/dev/null \
&& jq empty "$tmp" >/dev/null 2>&1; then
mv "$tmp" "$OUT_DIR/$name.json"
return 0
fi
rm -f "$tmp"
if [ "$allow_fallback" = "1" ] && [ "${KOMODO_PLAYWRIGHT_FALLBACK:-0}" = "1" ]; then
configure_playwright_runtime
if [ -z "${NODE_BIN:-}" ]; then
printf '%s\n' "Playwright fallback unavailable: node executable not found" >> "$ERROR_FILE"
rm -f "$tmp"
printf '%s\n' "failed to fetch JSON from $url" >> "$ERROR_FILE"
return 1
fi
maybe_set_cdp_endpoint
PLAYWRIGHT_CORE_PATH="${PLAYWRIGHT_CORE_PATH:-}"
if command -v playwright-cli >/dev/null 2>&1; then
PLAYWRIGHT_CLI_BIN="$(command -v playwright-cli)"
PLAYWRIGHT_CORE_PATH="$(CDPATH= cd -- "$(dirname "$PLAYWRIGHT_CLI_BIN")/../lib/node_modules/@playwright/cli/node_modules/playwright-core" 2>/dev/null && pwd || true)"
fi
PLAYWRIGHT_CORE_PATH="$PLAYWRIGHT_CORE_PATH" "$NODE_BIN" "$SCRIPT_DIR/fetch_with_playwright.js" "$url" "$tmp"
if jq empty "$tmp" >/dev/null 2>&1; then
mv "$tmp" "$OUT_DIR/$name.json"
return 0
fi
fi
rm -f "$tmp"
printf '%s\n' "failed to fetch JSON from $url" >> "$ERROR_FILE"
return 1
}
if ! fetch_json "wp-json-root" "https://komodostation.com/wp-json/"; then
printf '%s\n' "Komodo API unavailable or blocked; leaving Komodo reports empty." >> "$ERROR_FILE"
printf '%s\n' "Komodo fetch blocked; see $ERROR_FILE"
exit 0
fi
if ! fetch_json "product-controller-jpy" "https://komodostation.com/wp-json/wp/v2/product/413763"; then
printf '%s\n' "Komodo product fetch blocked; leaving Komodo reports empty." >> "$ERROR_FILE"
printf '%s\n' "Komodo fetch blocked; see $ERROR_FILE"
exit 0
fi
fetch_json "product-machine-jpy" "https://komodostation.com/wp-json/wp/v2/product/413772" || true
fetch_json "product-frame-jpy" "https://komodostation.com/wp-json/wp/v2/product/413776" || true
fetch_json "sections-controller-search" "https://komodostation.com/wp-json/wp/v2/sections?search=Steam%20Controller&per_page=100" || true
fetch_json "sections-machine-search" "https://komodostation.com/wp-json/wp/v2/sections?search=Steam%20Machine&per_page=100" || true
fetch_json "sections-frame-search" "https://komodostation.com/wp-json/wp/v2/sections?search=Steam%20Frame&per_page=100" || true
fetch_json "media-controller-search" "https://komodostation.com/wp-json/wp/v2/media?search=Steam%20Controller&per_page=100" || true
fetch_json "media-parent-product-controller" "https://komodostation.com/wp-json/wp/v2/media?parent=413763&per_page=100" || true
for optional_array in \
sections-controller-search \
sections-machine-search \
sections-frame-search \
media-controller-search \
media-parent-product-controller
do
if [ ! -f "$OUT_DIR/$optional_array.json" ]; then
printf '%s\n' "[]" > "$OUT_DIR/$optional_array.json"
fi
done
for section_report in \
sections-controller-search \
sections-machine-search \
sections-frame-search
do
for id in $(jq -r '.[].id' "$OUT_DIR/$section_report.json" 2>/dev/null || true); do
fetch_json "media-parent-section-$id" "https://komodostation.com/wp-json/wp/v2/media?parent=$id&per_page=100" || true
done
done
{
printf 'controller\t%s\n' "$(jq -r '.modified // "n/a"' "$OUT_DIR/product-controller-jpy.json" 2>/dev/null || printf 'n/a')"
printf 'machine\t%s\n' "$(jq -r '.modified // "n/a"' "$OUT_DIR/product-machine-jpy.json" 2>/dev/null || printf 'n/a')"
printf 'frame\t%s\n' "$(jq -r '.modified // "n/a"' "$OUT_DIR/product-frame-jpy.json" 2>/dev/null || printf 'n/a')"
} > "$REPORT_DIR/komodo-product-modified.tsv"
jq -r '.[]? | [.id,.date,.modified,.slug,.title.rendered] | @tsv' \
"$OUT_DIR/sections-controller-search.json" \
> "$REPORT_DIR/komodo-controller-sections.tsv"
jq -r '.[]? | [.id,.date,.modified,.slug,.title.rendered] | @tsv' \
"$OUT_DIR/sections-machine-search.json" \
> "$REPORT_DIR/komodo-machine-sections.tsv"
jq -r '.[]? | [.id,.date,.modified,.slug,.title.rendered] | @tsv' \
"$OUT_DIR/sections-frame-search.json" \
> "$REPORT_DIR/komodo-frame-sections.tsv"
jq -r '
.[]?
| select((.source_url + " " + .slug + " " + .title.rendered) | test("2026/|webm|mp4|avif|spec|manual"; "i"))
| [.id,.date,.modified,.slug,.mime_type,.post,.source_url]
| @tsv
' "$OUT_DIR/media-controller-search.json" > "$REPORT_DIR/komodo-controller-media-interesting.tsv"
write_section_media_report() {
sections_file="$1"
output_file="$2"
: > "$output_file"
for id in $(jq -r '.[].id' "$sections_file" 2>/dev/null || true); do
media_file="$OUT_DIR/media-parent-section-$id.json"
if [ -f "$media_file" ]; then
jq -r '
.[]?
| [.id,.date,.modified,.slug,.mime_type,.post,.source_url]
| @tsv
' "$media_file" >> "$output_file"
fi
done
}
write_section_media_report "$OUT_DIR/sections-machine-search.json" "$REPORT_DIR/komodo-machine-media.tsv"
write_section_media_report "$OUT_DIR/sections-frame-search.json" "$REPORT_DIR/komodo-frame-media.tsv"
jq -r '
.[]?
| select((.mime_type | startswith("image/")) or (.mime_type | startswith("video/")))
| [.id,.mime_type,.source_url]
| @tsv
' "$OUT_DIR"/media-*.json "$OUT_DIR"/media-parent-*.json 2>/dev/null \
| sort -u \
> "$REPORT_DIR/komodo-visual-assets.tsv"
printf '%s\n' \
"Saved Komodo API responses to $OUT_DIR" \
"Saved Komodo summaries to $REPORT_DIR"