@c-time/frelio-cms 1.3.6 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/functions/api/auth/callback.js +122 -0
- package/functions/api/storage/_middleware.js +1012 -0
- package/functions/api/storage/files/[uuid].js +19 -0
- package/functions/api/storage/list.js +8 -0
- package/functions/api/storage/rebuild/[year].js +14 -0
- package/functions/api/storage/upload-set.js +7 -0
- package/functions/api/storage/upload.js +7 -0
- package/functions/api/storage/years.js +7 -0
- package/package.json +7 -3
- package/workers/file-upload/package-lock.json +1606 -0
- package/workers/file-upload/package.json +14 -0
- package/workers/file-upload/src/controller/DIContainer.ts +103 -0
- package/workers/file-upload/src/controller/FileController.ts +248 -0
- package/workers/file-upload/src/domain/AuthEntity.ts +17 -0
- package/workers/file-upload/src/domain/FileEntity.ts +113 -0
- package/workers/file-upload/src/index.ts +134 -0
- package/workers/file-upload/src/infra/LoggerSingleton.ts +162 -0
- package/workers/file-upload/src/presenter/HttpPresenterImpl.ts +86 -0
- package/workers/file-upload/src/repository/AuthRepositoryPort.ts +11 -0
- package/workers/file-upload/src/repository/GitHubAuthRepositoryImpl.ts +58 -0
- package/workers/file-upload/src/repository/R2RepositoryImpl.ts +145 -0
- package/workers/file-upload/src/repository/R2RepositoryPort.ts +86 -0
- package/workers/file-upload/src/usecase/DeleteFileUseCase.ts +97 -0
- package/workers/file-upload/src/usecase/GetFileUseCase.ts +50 -0
- package/workers/file-upload/src/usecase/ListFilesUseCase.ts +52 -0
- package/workers/file-upload/src/usecase/RebuildIndexUseCase.ts +182 -0
- package/workers/file-upload/src/usecase/UpdateFileMetadataUseCase.ts +43 -0
- package/workers/file-upload/src/usecase/UploadFileUseCase.ts +62 -0
- package/workers/file-upload/src/usecase/UploadImageSetUseCase.ts +95 -0
- package/workers/file-upload/src/usecase/ValidateAuthUseCase.ts +26 -0
- package/workers/file-upload/tsconfig.json +13 -0
- package/workers/file-upload/wrangler.toml.example +11 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// functions/api/auth/callback.ts
|
|
2
|
+
function errorHtml(title, message) {
|
|
3
|
+
return `<!DOCTYPE html>
|
|
4
|
+
<html lang="ja">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>${title} - Frelio</title>
|
|
9
|
+
<style>
|
|
10
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
11
|
+
body {
|
|
12
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
13
|
+
background: #f5f5f5;
|
|
14
|
+
display: flex;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
align-items: center;
|
|
17
|
+
min-height: 100vh;
|
|
18
|
+
color: #333;
|
|
19
|
+
}
|
|
20
|
+
.card {
|
|
21
|
+
background: #fff;
|
|
22
|
+
border-radius: 12px;
|
|
23
|
+
box-shadow: 0 2px 12px rgba(0,0,0,0.1);
|
|
24
|
+
padding: 40px;
|
|
25
|
+
max-width: 480px;
|
|
26
|
+
width: 90%;
|
|
27
|
+
text-align: center;
|
|
28
|
+
}
|
|
29
|
+
.icon {
|
|
30
|
+
font-size: 48px;
|
|
31
|
+
margin-bottom: 16px;
|
|
32
|
+
}
|
|
33
|
+
h1 {
|
|
34
|
+
font-size: 20px;
|
|
35
|
+
font-weight: 600;
|
|
36
|
+
margin-bottom: 12px;
|
|
37
|
+
}
|
|
38
|
+
p {
|
|
39
|
+
font-size: 14px;
|
|
40
|
+
color: #666;
|
|
41
|
+
line-height: 1.6;
|
|
42
|
+
margin-bottom: 24px;
|
|
43
|
+
}
|
|
44
|
+
a {
|
|
45
|
+
display: inline-block;
|
|
46
|
+
background: #1976d2;
|
|
47
|
+
color: #fff;
|
|
48
|
+
text-decoration: none;
|
|
49
|
+
padding: 10px 24px;
|
|
50
|
+
border-radius: 6px;
|
|
51
|
+
font-size: 14px;
|
|
52
|
+
font-weight: 500;
|
|
53
|
+
transition: background 0.2s;
|
|
54
|
+
}
|
|
55
|
+
a:hover { background: #1565c0; }
|
|
56
|
+
</style>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
<div class="card">
|
|
60
|
+
<div class="icon">\u26A0\uFE0F</div>
|
|
61
|
+
<h1>${title}</h1>
|
|
62
|
+
<p>${message}</p>
|
|
63
|
+
<a href="/">\u30C0\u30C3\u30B7\u30E5\u30DC\u30FC\u30C9\u306B\u623B\u308B</a>
|
|
64
|
+
</div>
|
|
65
|
+
</body>
|
|
66
|
+
</html>`;
|
|
67
|
+
}
|
|
68
|
+
var onRequestGet = async (context) => {
|
|
69
|
+
const url = new URL(context.request.url);
|
|
70
|
+
const code = url.searchParams.get("code");
|
|
71
|
+
if (!code) {
|
|
72
|
+
return new Response(
|
|
73
|
+
errorHtml("\u8A8D\u8A3C\u30A8\u30E9\u30FC", "\u8A8D\u8A3C\u30B3\u30FC\u30C9\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u30C0\u30C3\u30B7\u30E5\u30DC\u30FC\u30C9\u306B\u623B\u3063\u3066\u518D\u5EA6\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),
|
|
74
|
+
{ status: 400, headers: { "Content-Type": "text/html; charset=utf-8" } }
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const clientId = context.env.GITHUB_CLIENT_ID || context.env.VITE_GITHUB_CLIENT_ID;
|
|
78
|
+
if (!clientId) {
|
|
79
|
+
return new Response(
|
|
80
|
+
errorHtml("\u30B5\u30FC\u30D0\u30FC\u8A2D\u5B9A\u30A8\u30E9\u30FC", "\u30B5\u30FC\u30D0\u30FC\u306E\u8A2D\u5B9A\u306B\u554F\u984C\u304C\u3042\u308A\u307E\u3059\u3002\u7BA1\u7406\u8005\u306B\u304A\u554F\u3044\u5408\u308F\u305B\u304F\u3060\u3055\u3044\u3002"),
|
|
81
|
+
{ status: 500, headers: { "Content-Type": "text/html; charset=utf-8" } }
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const tokenResponse = await fetch(
|
|
86
|
+
"https://github.com/login/oauth/access_token",
|
|
87
|
+
{
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers: {
|
|
90
|
+
Accept: "application/json",
|
|
91
|
+
"Content-Type": "application/json"
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
client_id: clientId,
|
|
95
|
+
client_secret: context.env.GITHUB_CLIENT_SECRET,
|
|
96
|
+
code
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
const tokenData = await tokenResponse.json();
|
|
101
|
+
if (tokenData.error) {
|
|
102
|
+
return new Response(
|
|
103
|
+
errorHtml(
|
|
104
|
+
"\u8A8D\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
105
|
+
"\u8A8D\u8A3C\u30B3\u30FC\u30C9\u304C\u7121\u52B9\u307E\u305F\u306F\u671F\u9650\u5207\u308C\u3067\u3059\u3002\u30C0\u30C3\u30B7\u30E5\u30DC\u30FC\u30C9\u306B\u623B\u3063\u3066\u30D6\u30E9\u30A6\u30B6\u3092\u30EA\u30ED\u30FC\u30C9\u3057\u3001\u518D\u5EA6\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
|
|
106
|
+
),
|
|
107
|
+
{ status: 400, headers: { "Content-Type": "text/html; charset=utf-8" } }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const origin = url.origin;
|
|
111
|
+
const redirectUrl = `${origin}/auth/callback?token=${tokenData.access_token}`;
|
|
112
|
+
return Response.redirect(redirectUrl, 302);
|
|
113
|
+
} catch {
|
|
114
|
+
return new Response(
|
|
115
|
+
errorHtml("\u8A8D\u8A3C\u30A8\u30E9\u30FC", "\u8A8D\u8A3C\u51E6\u7406\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u30C0\u30C3\u30B7\u30E5\u30DC\u30FC\u30C9\u306B\u623B\u3063\u3066\u518D\u5EA6\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),
|
|
116
|
+
{ status: 500, headers: { "Content-Type": "text/html; charset=utf-8" } }
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
export {
|
|
121
|
+
onRequestGet
|
|
122
|
+
};
|