Skip to content

Commit

Permalink
public link password support
Browse files Browse the repository at this point in the history
  • Loading branch information
diocas committed Dec 6, 2021
1 parent d7153c0 commit 7d3b63c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
19 changes: 14 additions & 5 deletions common/fileAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const DavProperties = [DavPermissions]

const plState = {
isPublicLink: false,
plToken: null
plToken: null,
publicLinkPassword: null
}

const plMutations = {
Expand All @@ -13,6 +14,9 @@ const plMutations = {
},
PL_TOKEN(state, token) {
state.plToken = token
},
PL_PASSWORD(state, password) {
state.publicLinkPassword = password
}
}

Expand All @@ -22,13 +26,17 @@ const plGetters = {
},
plToken: (state) => {
return state.plToken
},
publicLinkPassword: (state) => {
return state.publicLinkPassword
}
}

const getContents = (state, client) => {

if (state.isPublicLink) {
return new Promise((resolve, reject) => {
client.publicFiles.download(state.plToken, state.currentFile).then(async (res) => {
client.publicFiles.download(state.plToken, state.currentFile, state.publicLinkPassword).then(async (res) => {
res.statusCode = res.status
resolve({
response: res,
Expand All @@ -51,7 +59,7 @@ const getContents = (state, client) => {

const putContents = (state, client) => {
if (state.isPublicLink) {
return client.publicFiles.putFileContents(state.plToken, state.currentFile, null, state.text, {
return client.publicFiles.putFileContents(state.plToken, state.currentFile, state.publicLinkPassword, state.text, {
previousEntityTag: state.currentETag
})
} else {
Expand All @@ -63,7 +71,7 @@ const putContents = (state, client) => {

const fileInfo = (state, client) => {
if (state.isPublicLink) {
return client.publicFiles.getFileInfo(state.plToken + state.currentFile, null, DavProperties)
return client.publicFiles.getFileInfo(state.plToken + state.currentFile, state.publicLinkPassword, DavProperties)
} else {
return client.files.fileInfo(state.currentFile, DavProperties)
}
Expand All @@ -79,13 +87,14 @@ const filePermissions = (state, client) => {
})
}

const getFilePath = (commit, isPublic, filePath) => {
const getFilePath = (commit, isPublic, filePath, publicLinkPassword = null) => {
if (isPublic) {
const path = filePath.split('/')
path.shift() // remove empty first elem
const token = path.shift()
commit('PL_TOKEN', token)
commit('PUBLIC_LINK', true)
commit('PL_PASSWORD', publicLinkPassword)
return '/' + path.join('/')
} else {
return filePath
Expand Down
4 changes: 3 additions & 1 deletion jupyter/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ import { mapActions, mapGetters } from 'vuex'
export default {
name: 'Jupyter Viewer',
computed: {
...mapGetters('Files', ['publicLinkPassword']),
...mapGetters('Jupyter Viewer', ['isLoading', 'renderedNotebook', 'lastError'])
},
mounted() {
const filePath = `/${this.$route.params.filePath.split('/').filter(Boolean).join('/')}`
this.loadFile({
filePath: filePath,
client: this.$client,
public: this.$route.name === 'jupyter-public'
public: this.$route.name === 'jupyter-public',
publicLinkPassword: this.publicLinkPassword
})
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion jupyter/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const actions = {
commit('ERROR', '')
},
loadFile({ commit }, payload) {
const filePath = getFilePath(commit, payload.public, payload.filePath)
const filePath = getFilePath(commit, payload.public, payload.filePath, payload.publicLinkPassword)
const client = payload.client

commit('LOADING', true)
Expand Down
5 changes: 4 additions & 1 deletion text-editor/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
},
computed: {
...mapGetters(['activeFile']),
...mapGetters('Files', ['publicLinkPassword']),
...mapGetters('Text Editor', ['currentContent', 'lastError', 'isReadOnly', 'isTouched'])
},
mounted() {
Expand All @@ -74,7 +75,9 @@ export default {
this.loadFile({
filePath: filePath,
client: this.$client,
public: this.$route.name === 'text-editor-public'
public: this.$route.name === 'text-editor-public',
publicLinkPassword: this.publicLinkPassword
})
document.addEventListener('keydown', this.handleSKey, false)
window.addEventListener('beforeunload', this.handleUnload)
Expand Down
2 changes: 1 addition & 1 deletion text-editor/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const actions = {
},
loadFile({ commit, state }, payload) {
const client = payload.client
const filePath = getFilePath(commit, payload.public, payload.filePath)
const filePath = getFilePath(commit, payload.public, payload.filePath, payload.publicLinkPassword)

commit('LOADING', true)
commit('CURRENT_FILE', filePath)
Expand Down

0 comments on commit 7d3b63c

Please sign in to comment.