Spaces:
Runtime error
Runtime error
Update src/components/menu-bar/google-drive-save.jsx
Browse files
src/components/menu-bar/google-drive-save.jsx
CHANGED
@@ -37,42 +37,39 @@ class GoogleDriveSave extends React.Component {
|
|
37 |
this.handleCloseModal();
|
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 |
-
this.fetchDriveFiles(event.data.token);
|
64 |
-
}
|
65 |
-
};
|
66 |
-
window.addEventListener("message", messageListener);
|
67 |
-
|
68 |
-
const authUrl = `https://accounts.google.com/o/oauth2/auth?` +
|
69 |
-
`client_id=${CLIENT_ID}` +
|
70 |
-
`&redirect_uri=${encodeURIComponent(REDIRECT_URI)}` +
|
71 |
-
`&response_type=token` +
|
72 |
-
`&scope=${encodeURIComponent(SCOPES)}`;
|
73 |
-
|
74 |
-
window.open(authUrl, "_blank", "width=500,height=600");
|
75 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
fetchDriveFiles = async (accessToken) => {
|
78 |
this.setState({isLoading: true});
|
@@ -248,31 +245,37 @@ class GoogleDriveSave extends React.Component {
|
|
248 |
);
|
249 |
}
|
250 |
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
target="_blank"
|
268 |
-
rel="noopener noreferrer"
|
269 |
-
className={styles.linkUrl}
|
270 |
>
|
271 |
-
|
272 |
-
</
|
273 |
</div>
|
274 |
-
|
275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
|
277 |
render() {
|
278 |
return (
|
@@ -318,15 +321,16 @@ class GoogleDriveSave extends React.Component {
|
|
318 |
}
|
319 |
};
|
320 |
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
}
|
|
|
330 |
|
331 |
handleLoadFile = (project) => {
|
332 |
const PROXY_URL = "https://soiz1-drive-proxy.hf.space/?file_id=";
|
|
|
37 |
this.handleCloseModal();
|
38 |
}
|
39 |
};
|
40 |
+
startGoogleLogin = () => {
|
41 |
+
// 既存のトークン情報をクリア
|
42 |
+
localStorage.removeItem('googleDriveAccessToken');
|
43 |
+
localStorage.removeItem('googleDriveAccountEmail');
|
44 |
+
localStorage.removeItem('googleDriveAccountName');
|
45 |
+
|
46 |
+
const CLIENT_ID = "1033286471224-n9mv8l869fqikubj2e8q92n8ige3qr6r.apps.googleusercontent.com";
|
47 |
+
const REDIRECT_URI = "https://soiz1-s4s-upload.hf.space/close2";
|
48 |
+
const SCOPES = "https://www.googleapis.com/auth/drive.file";
|
49 |
+
|
50 |
+
const messageListener = (event) => {
|
51 |
+
if (event.data.token) {
|
52 |
+
window.removeEventListener("message", messageListener);
|
53 |
+
this.setState({
|
54 |
+
accessToken: event.data.token,
|
55 |
+
currentAccountEmail: event.data.email || null,
|
56 |
+
currentAccountName: event.data.name || null,
|
57 |
+
isModalOpen: true
|
58 |
+
});
|
59 |
+
|
60 |
+
this.fetchDriveFiles(event.data.token);
|
61 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
};
|
63 |
+
window.addEventListener("message", messageListener);
|
64 |
+
|
65 |
+
const authUrl = `https://accounts.google.com/o/oauth2/auth?` +
|
66 |
+
`client_id=${CLIENT_ID}` +
|
67 |
+
`&redirect_uri=${encodeURIComponent(REDIRECT_URI)}` +
|
68 |
+
`&response_type=token` +
|
69 |
+
`&scope=${encodeURIComponent(SCOPES)}`;
|
70 |
+
|
71 |
+
window.open(authUrl, "_blank", "width=500,height=600");
|
72 |
+
};
|
73 |
|
74 |
fetchDriveFiles = async (accessToken) => {
|
75 |
this.setState({isLoading: true});
|
|
|
245 |
);
|
246 |
}
|
247 |
|
248 |
+
renderShareLink(fileId) {
|
249 |
+
const SHORT_URL = "https://s4.rf.gd/";
|
250 |
+
|
251 |
+
return (
|
252 |
+
<div className={styles.linkContainer}>
|
253 |
+
<div className={styles.linkHeader}>
|
254 |
+
<span>共有リンク:</span>
|
255 |
+
<button
|
256 |
+
onClick={() => this.copyToClipboard(`${SHORT_URL}${fileId}`)}
|
257 |
+
className={styles.copyButton}
|
258 |
+
>
|
259 |
+
リンクをコピー
|
260 |
+
</button>
|
261 |
+
<button
|
262 |
+
onClick={() => this.copyToClipboard(fileId)}
|
263 |
+
className={styles.copyButton}
|
|
|
|
|
|
|
264 |
>
|
265 |
+
IDのみコピー
|
266 |
+
</button>
|
267 |
</div>
|
268 |
+
<a
|
269 |
+
href={`${SHORT_URL}${fileId}`}
|
270 |
+
target="_blank"
|
271 |
+
rel="noopener noreferrer"
|
272 |
+
className={styles.linkUrl}
|
273 |
+
>
|
274 |
+
{`${SHORT_URL}${fileId}`}
|
275 |
+
</a>
|
276 |
+
</div>
|
277 |
+
);
|
278 |
+
}
|
279 |
|
280 |
render() {
|
281 |
return (
|
|
|
321 |
}
|
322 |
};
|
323 |
|
324 |
+
handleNewFile = async () => {
|
325 |
+
try {
|
326 |
+
await this.saveToGoogleDrive(null, null);
|
327 |
+
alert("success", "新規保存しました");
|
328 |
+
this.fetchDriveFiles(this.state.accessToken);
|
329 |
+
} catch (error) {
|
330 |
+
console.error("新規保存エラー:", error);
|
331 |
+
alert("error", "新規保存に失敗しました");
|
332 |
+
}
|
333 |
+
};
|
334 |
|
335 |
handleLoadFile = (project) => {
|
336 |
const PROXY_URL = "https://soiz1-drive-proxy.hf.space/?file_id=";
|