soiz1 commited on
Commit
9a7ef9e
·
verified ·
1 Parent(s): 6be52c1

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
- startGoogleLogin = () => {
41
- const CLIENT_ID = "1033286471224-n9mv8l869fqikubj2e8q92n8ige3qr6r.apps.googleusercontent.com";
42
- const REDIRECT_URI = "https://soiz1-s4s-upload.hf.space/close2";
43
- const SCOPES = "https://www.googleapis.com/auth/drive.file";
44
-
45
- const messageListener = (event) => {
46
- if (event.data.token) {
47
- window.removeEventListener("message", messageListener);
48
- this.setState({
49
- accessToken: event.data.token,
50
- currentAccountEmail: event.data.email || null,
51
- currentAccountName: event.data.name || null,
52
- isModalOpen: true
53
- });
54
-
55
- localStorage.setItem('googleDriveAccessToken', event.data.token);
56
- if (event.data.email) {
57
- localStorage.setItem('googleDriveAccountEmail', event.data.email);
58
- }
59
- if (event.data.name) {
60
- localStorage.setItem('googleDriveAccountName', event.data.name);
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
- renderShareLink(fileId) {
252
- const SHORT_URL = "https://s4.rf.gd/";
253
-
254
- return (
255
- <div className={styles.linkContainer}>
256
- <div className={styles.linkHeader}>
257
- <span>共有リンク:</span>
258
- <button
259
- onClick={() => this.copyToClipboard(`${SHORT_URL}${fileId}`)}
260
- className={styles.copyButton}
261
- >
262
- コピー
263
- </button>
264
- </div>
265
- <a
266
- href={`${SHORT_URL}${fileId}`}
267
- target="_blank"
268
- rel="noopener noreferrer"
269
- className={styles.linkUrl}
270
  >
271
- {`${SHORT_URL}${fileId}`}
272
- </a>
273
  </div>
274
- );
275
- }
 
 
 
 
 
 
 
 
 
276
 
277
  render() {
278
  return (
@@ -318,15 +321,16 @@ class GoogleDriveSave extends React.Component {
318
  }
319
  };
320
 
321
- handleNewFile = async () => {
322
- try {
323
- await this.saveToGoogleDrive(null, null);
324
- alert("success", "新規保存しました");
325
- } catch (error) {
326
- console.error("新規保存エラー:", error);
327
- alert("error", "新規保存に失敗しました");
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=";