Skip to content

Commit 2e25cb2

Browse files
authored
Merge pull request #136 from KOU050223/AliceWonerfulWorld/feature/default-sort-year-desc
add: アプリを持っていない人でもQRコードを読み込めば、相手のユーザーの視聴履歴を閲覧できるサイトを実装。
2 parents d7e37d4 + 6bf28eb commit 2e25cb2

File tree

12 files changed

+888
-4
lines changed

12 files changed

+888
-4
lines changed

docs/guest-site-deploy.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# ゲストサイト(viewer)デプロイ方法
2+
3+
## 概要
4+
5+
このドキュメントでは、Firebase Hostingのマルチサイト機能を使用して、viewerアプリを別のサイトとしてデプロイする方法を説明します。
6+
7+
## 前提条件
8+
9+
- Firebase CLIがインストールされている
10+
- Firebaseプロジェクト(animeishi-73560)にアクセス権限がある
11+
- Flutterアプリが既にメインサイトにデプロイされている
12+
13+
## デプロイ手順
14+
15+
### 1. Firebase側の設定
16+
17+
#### 1.1 新しいサイトの作成
18+
19+
1. **Firebase Console**にアクセス
20+
2. **Hosting**ページに移動
21+
3. **「別のサイトを追加」**ボタンをクリック
22+
4. サイトIDを入力:`animeishi-viewer`
23+
5. **「サイトを追加」**をクリック
24+
25+
#### 1.2 認証済みドメインの追加(必要に応じて)
26+
27+
1. **Authentication****Settings****Authorized domains**
28+
2. **「ドメインを追加」**をクリック
29+
3. `animeishi-viewer.web.app`を追加
30+
31+
### 2. ローカル環境での設定
32+
33+
#### 2.1 viewerディレクトリに移動
34+
35+
```bash
36+
cd viewer
37+
```
38+
39+
#### 2.2 Firebase初期化
40+
41+
```bash
42+
firebase init hosting
43+
```
44+
45+
設定内容:
46+
- **Public directory**: `public`
47+
- **Single-page app**: `No`
48+
- **GitHub自動デプロイ**: `No`
49+
- **既存ファイルの上書き**: `N`(既存のindex.htmlを保持)
50+
51+
#### 2.3 ターゲット設定
52+
53+
```bash
54+
firebase target:apply hosting viewer-site animeishi-viewer
55+
```
56+
57+
#### 2.4 firebase.jsonの設定
58+
59+
```json
60+
{
61+
"hosting": {
62+
"target": "viewer-site",
63+
"public": "public",
64+
"ignore": [
65+
"firebase.json",
66+
"**/.*",
67+
"**/node_modules/**"
68+
],
69+
"rewrites": [
70+
{
71+
"source": "/user/**",
72+
"destination": "/user.html"
73+
}
74+
]
75+
}
76+
}
77+
```
78+
79+
#### 2.5 .firebasercの確認
80+
81+
```json
82+
{
83+
"projects": {
84+
"default": "animeishi-73560"
85+
},
86+
"targets": {
87+
"animeishi-73560": {
88+
"hosting": {
89+
"viewer-site": [
90+
"animeishi-viewer"
91+
]
92+
}
93+
}
94+
}
95+
}
96+
```
97+
98+
### 3. デプロイ
99+
100+
#### 3.1 viewerサイトのデプロイ
101+
102+
```bash
103+
firebase deploy --only hosting:viewer-site
104+
```
105+
106+
#### 3.2 デプロイ確認
107+
108+
- **URL**: `https://animeishi-viewer.web.app`
109+
- Firebase Consoleでデプロイ履歴を確認
110+
111+
### 4. Flutterアプリの設定更新
112+
113+
#### 4.1 QRコードURLの更新
114+
115+
`lib/ui/home/view/home_page.dart`を編集:
116+
117+
```dart
118+
final String qrData = user?.uid != null
119+
? "https://animeishi-viewer.web.app/user/${user!.uid}"
120+
: "No UID";
121+
```
122+
123+
#### 4.2 Flutterアプリの再デプロイ
124+
125+
```bash
126+
flutter build web
127+
firebase deploy --only hosting
128+
```
129+
130+
## サイト構成
131+
132+
### メインサイト(Flutterアプリ)
133+
- **URL**: `https://animeishi-73560.web.app`
134+
- **用途**: アプリのメイン機能
135+
- **デプロイ先**: プロジェクトのルート
136+
137+
### ゲストサイト(viewerアプリ)
138+
- **URL**: `https://animeishi-viewer.web.app`
139+
- **用途**: ユーザーの視聴履歴表示
140+
- **デプロイ先**: `viewer`ディレクトリ
141+
142+
## トラブルシューティング
143+
144+
### よくある問題
145+
146+
#### 1. デプロイエラー
147+
148+
```bash
149+
# ログイン確認
150+
firebase login
151+
152+
# プロジェクト確認
153+
firebase projects:list
154+
155+
# ターゲット確認
156+
firebase target
157+
```
158+
159+
#### 2. ファイルが見つからない
160+
161+
```bash
162+
# ファイル構造確認
163+
ls -la public/
164+
165+
# 必要なファイルの存在確認
166+
ls -la public/index.html
167+
ls -la public/assets/js/
168+
```
169+
170+
#### 3. Firebase初期化エラー
171+
172+
```bash
173+
# 設定ファイルの確認
174+
cat firebase.json
175+
cat .firebaserc
176+
177+
# 必要に応じて再初期化
178+
firebase init hosting
179+
```
180+
181+
### デバッグ方法
182+
183+
#### 1. ローカルテスト
184+
185+
```bash
186+
# ローカルサーバー起動
187+
firebase serve --only hosting:viewer-site
188+
189+
# ブラウザで確認
190+
# http://localhost:5000
191+
```
192+
193+
#### 2. ログ確認
194+
195+
```bash
196+
# デプロイログの詳細表示
197+
firebase deploy --only hosting:viewer-site --debug
198+
```
199+
200+
## メンテナンス
201+
202+
### 定期的な作業
203+
204+
1. **セキュリティ更新**: Firebase SDKの更新
205+
2. **パフォーマンス監視**: ページ読み込み速度の確認
206+
3. **エラー監視**: ブラウザコンソールでのエラー確認
207+
208+
### 更新手順
209+
210+
1. **コード変更**
211+
2. **ローカルテスト**
212+
3. **デプロイ**
213+
4. **動作確認**
214+
215+
## 参考リンク
216+
217+
- [Firebase Hosting マルチサイト](https://firebase.google.com/docs/hosting/multisites?hl=ja)
218+
- [Firebase CLI リファレンス](https://firebase.google.com/docs/cli?hl=ja)
219+
- [Firebase Hosting クイックスタート](https://firebase.google.com/docs/hosting/quickstart?hl=ja)
220+
221+
## 更新履歴
222+
223+
- 2025/08/16: 初版作成
224+
- マルチサイト機能を使用したviewerアプリのデプロイ方法を追加

firestore.rules

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ service cloud.firestore {
1111
return request.auth != null && request.auth.uid == userId;
1212
}
1313

14-
// ユーザー個人データ - 本人のみアクセス可能
14+
// ユーザー個人データ - プロフィールは公開読み取り、編集は本人のみ
1515
match /users/{userId} {
16-
allow read, write: if isOwner(userId);
17-
16+
allow read: if true; // プロフィールを公開読み取りに変更
17+
allow write: if isOwner(userId);
18+
1819
// ユーザーのサブコレクション(selectedAnime, meishies, friends等)
1920
match /{subcollection}/{document} {
20-
allow read, write: if isOwner(userId);
21+
allow read: if subcollection == "selectedAnime";
22+
allow write: if isOwner(userId);
2123
}
2224
}
2325

lib/ui/home/view/home_page.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ class _HomeTabPageState extends State<HomeTabPage> {
209209
@override
210210
Widget build(BuildContext context) {
211211
final User? user = FirebaseAuth.instance.currentUser;
212+
213+
final String qrData = user?.uid != null
214+
? "https://animeishi-viewer.web.app/user/${user!.uid}"
215+
: "No UID";
216+
212217
final String? currentUserId = user?.uid;
213218

214219
// ユーザーIDが変更された場合のみ処理(無限ループを防ぐ)
@@ -370,6 +375,7 @@ class _HomeTabPageState extends State<HomeTabPage> {
370375
color: Colors.grey,
371376
),
372377
),
378+
373379
],
374380
),
375381
),

viewer/.firebaserc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"projects": {
3+
"default": "animeishi-73560"
4+
},
5+
"targets": {
6+
"animeishi-73560": {
7+
"hosting": {
8+
"viewer-site": [
9+
"animeishi-viewer"
10+
]
11+
}
12+
}
13+
},
14+
"etags": {}
15+
}

viewer/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# アニ名刺 ビューアー
2+
3+
アニメ視聴履歴を共有するためのWebサイトです。
4+
5+
## 機能
6+
7+
- QRコードでユーザーIDを読み取り、視聴履歴を表示
8+
- ユーザープロフィール表示
9+
- 視聴済みアニメ一覧表示
10+
- レスポンシブデザイン対応
11+
12+
## デプロイ手順
13+
14+
### 1. Firebase CLIのインストール
15+
16+
```bash
17+
npm install -g firebase-tools
18+
```
19+
20+
### 2. Firebaseにログイン
21+
22+
```bash
23+
firebase login
24+
```
25+
26+
### 3. プロジェクトの初期化
27+
28+
```bash
29+
cd viewer
30+
firebase init hosting
31+
```
32+
33+
### 4. デプロイ
34+
35+
```bash
36+
firebase deploy
37+
```
38+
39+
## ファイル構成
40+
41+
```
42+
viewer/
43+
├── public/
44+
│ ├── index.html # メインページ
45+
│ ├── user.html # ユーザー詳細ページ
46+
│ └── assets/
47+
│ ├── css/
48+
│ │ └── style.css # スタイルシート
49+
│ └── js/
50+
│ ├── app.js # メインアプリケーション
51+
│ └── firebase-config.js # Firebase設定
52+
├── firebase.json # Firebase設定
53+
└── .firebaserc # プロジェクト設定
54+
```
55+
56+
## URL構成
57+
58+
- `/` - ランディングページ
59+
- `/user/{userId}` - ユーザー詳細ページ
60+
61+
## 技術スタック
62+
63+
- HTML5
64+
- CSS3
65+
- JavaScript (ES6+)
66+
- Firebase Hosting
67+
- Firebase Firestore

viewer/firebase.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"hosting": {
3+
"target": "viewer-site",
4+
"public": "public",
5+
"ignore": [
6+
"firebase.json",
7+
"**/.*",
8+
"**/node_modules/**"
9+
],
10+
"rewrites": [
11+
{
12+
"source": "/user/**",
13+
"destination": "/user.html"
14+
}
15+
]
16+
}
17+
}

0 commit comments

Comments
 (0)