diff --git a/src/store/index.js b/src/store/index.js index 85f9a5f..736e59e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -14,6 +14,7 @@ import { addDoc, query, where, + limit, getDocs, doc, deleteDoc, @@ -29,6 +30,7 @@ export default new Vuex.Store({ access_token: null, docs: [], loading: false, + errorMessage: "", }, mutations: { setUser(state, user) { @@ -43,6 +45,9 @@ export default new Vuex.Store({ setAccessToken(state, access_token) { state.access_token = access_token; }, + setErrorMessage(state, errorMessage) { + state.errorMessage = errorMessage; + }, }, actions: { async signin({ commit, dispatch }) { @@ -282,7 +287,7 @@ export default new Vuex.Store({ endColumnIndex: 11, }, description: - "Protecting header row (needed for auto-archiver)", + "Protecting header row (needed for auto-archiver), do not modify archiving column names, you can add and move columns around when no 'Archive in Progress' is present in the 'Archive status' column.", warningOnly: true, }, }, @@ -317,5 +322,45 @@ export default new Vuex.Store({ console.error("add (firebase.js): ", error); } }, + + async enable({ state, dispatch, commit }, { spreadsheetId }) { + commit("setLoading", true); + commit("setErrorMessage", ""); + + try { + // fetch existing sheet + const sheetToEnable = await gapi.client.sheets.spreadsheets.get({ + spreadsheetId: spreadsheetId, + }); + + const q = query( + collection(firebaseFirestore, "sheets"), + where("uid", "==", state.user.uid), + where("sheetId", "==", spreadsheetId), + limit(1) + ); + + const response = await getDocs(q); + if(response.docs.length > 0) { + throw "Sheet already enabled"; + } + + const col = await collection(firebaseFirestore, "sheets"); + await addDoc(col, { + sheetId: spreadsheetId, + url: sheetToEnable.result.spreadsheetUrl, + timestamp: Date.now(), + uid: state.user.uid, + lastArchived: null, + name: sheetToEnable.result.properties.title, + }); + + dispatch("getDocs"); + } catch (error) { + commit("setErrorMessage", `Unable to add sheet: ${JSON.stringify(error)}`); + commit("setLoading", false); + console.error("add (firebase.js): ", error); + } + }, }, }); diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 967e5b9..ae49cca 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -25,27 +25,38 @@ >associated article.

+

How archiving a Google Spreadsheet works

+ + + + + + +
Manage new auto-archiver sheets
+ + + Create a new auto-archiver sheet +
  1. Press "create" to create a new archiving Google Sheet
  2. -
  3. - Add links to the "Link" column. They will be archived every 15 - minutes, or you can trigger a manual archive below -
  4. This sheet will be shared with the service account necessary for Bellingcat's archiving server
  5. -
  6. - You can modify and share the Google Sheet subsequently, but do - not edit the column names in the header row or remove the - service account from the shared users -
  7. +
  8. The sheet will appear in your list
-
-
- - Create a new auto archiver sheet - Create Sign in with a Google account + to continue + + + + + Enable the auto-archiver in an existing sheet + +
    +
  1. + Invite + bellingcat-auto-archiver-api@bellingcat-auto-archiver-b85db.iam.gserviceaccount.com + into your spreadsheet +
  2. + +
  3. + Make sure you have the following mandatory column names: +
      +
    • Link where you will put the URLs.
    • +
    • + Archive Status to monitor progress and success + of archiver +
    • +
    • + Archive location where the link to the archived + content is added +
    • +
    +
  4. +
  5. + Add any of the following optional column names: +
      +
    • + Archive date info on when archiving occurred +
    • +
    • + Thumbnail an image preview from archived media +
    • +
    • + Upload timestamp online content creation date +
    • +
    • Upload title title
    • +
    • Textual content text content
    • +
    • Screenshot link to page screenshot
    • +
    • + Hash content hash (for integrity purposes) +
    • +
    +
  6. +
  7. Paste the Google Sheet URL
  8. +
  9. Press "enable" to add the Google Sheet to your list
  10. +
  11. + Manually check archiving is working and re-check the steps above + if it is not +
  12. +
+ {{ $store.state.errorMessage }} + + Enable + Sign in with a Google account to continue - - @@ -83,12 +177,23 @@ export default { data() { return { docName: "Auto archiver sheet", + spreadsheetUrl: "", }; }, computed: { user() { return this.$store.state.user; }, + spreadsheetId() { + if ( + this.spreadsheetUrl.startsWith("http") && + this.spreadsheetUrl.split("/").length >= 6 + ) { + return this.spreadsheetUrl.split("/")[5]; + } + return this.spreadsheetUrl; + }, }, + methods: {}, };