soiz1 commited on
Commit
af70e71
·
verified ·
1 Parent(s): e1c8981

Update src/components/menu-bar/google-drive-save.jsx

Browse files
src/components/menu-bar/google-drive-save.jsx CHANGED
@@ -703,13 +703,45 @@ class GoogleDriveSave extends React.Component {
703
  }
704
  };
705
 
706
- handleShareFile = (fileId) => {
707
  if (this.state.isProcessing) return;
708
 
709
- const SHARE_URL = "https://scratch-school.ct.ws/upload?id=";
710
- window.open(`${SHARE_URL}${fileId}`, "_blank");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711
  };
712
-
713
  handleDeleteFile = async (project, thumbnailFiles) => {
714
  if (this.state.isProcessing) return;
715
 
 
703
  }
704
  };
705
 
706
+ handleShareFile = async (fileId) => {
707
  if (this.state.isProcessing) return;
708
 
709
+ this.setState({ isProcessing: true });
710
+ try {
711
+ // ファイルを公開設定(anyoneに閲覧権限を付与)
712
+ await fetch(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions`, {
713
+ method: "POST",
714
+ headers: {
715
+ "Authorization": `Bearer ${this.state.accessToken}`,
716
+ "Content-Type": "application/json",
717
+ },
718
+ body: JSON.stringify({
719
+ type: "anyone",
720
+ role: "reader",
721
+ }),
722
+ });
723
+
724
+ const SHARE_URL = "https://scratch-school.ct.ws/upload?id=";
725
+ const shortUrl = `${SHARE_URL}${fileId}`;
726
+
727
+ // 短縮URLをクリップボードにコピー
728
+ navigator.clipboard.writeText(shortUrl)
729
+ .then(() => {
730
+ this.showAlert("success", "公開リンクをクリップボードにコピーしました");
731
+ // 新しいタブで公開ページを開く
732
+ window.open(shortUrl, "_blank");
733
+ })
734
+ .catch(() => {
735
+ this.showAlert("error", "リンクのコピーに失敗しました");
736
+ });
737
+
738
+ } catch (error) {
739
+ console.error("公開エラー:", error);
740
+ this.showAlert("error", "ファイルの公開に失敗しました");
741
+ } finally {
742
+ this.setState({ isProcessing: false });
743
+ }
744
  };
 
745
  handleDeleteFile = async (project, thumbnailFiles) => {
746
  if (this.state.isProcessing) return;
747