Skip to content

Commit

Permalink
fix: Image plugin now handles asterisks
Browse files Browse the repository at this point in the history
  • Loading branch information
billyc committed Mar 28, 2022
1 parent 0ec9cc8 commit e216e4b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
67 changes: 55 additions & 12 deletions src/charts/slideshow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import { Vue, Component, Watch, Prop } from 'vue-property-decorator'
import { VueperSlides, VueperSlide } from 'vueperslides'
import 'vueperslides/dist/vueperslides.css'
import { FileSystemConfig } from '@/Globals'
import { FileSystemConfig, Status } from '@/Globals'
import HTTPFileSystem from '@/js/HTTPFileSystem'
import { hasOwnProperty } from 'vega'
import SVNFileSystem from '@/js/HTTPFileSystem'
import { findMatchingGlobInFiles } from '@/js/util'
@Component({ components: { VueperSlides, VueperSlide } })
export default class VueComponent extends Vue {
Expand All @@ -40,15 +41,16 @@ export default class VueComponent extends Vue {
private slides: any[] = []
// true for absolute URLs
private r: RegExp = new RegExp('^(?:[a-z]+:)?//', 'i')
private absoluteUrl: RegExp = new RegExp('^(?:[a-z]+:)?//', 'i')
private fileApi!: SVNFileSystem
private mounted() {
const fileApi = new HTTPFileSystem(this.fileSystemConfig)
private async mounted() {
this.fileApi = new HTTPFileSystem(this.fileSystemConfig)
if (this.config != null) Object.assign(this.options, this.config)
// Delete slide property because this is only used in the loop
if (hasOwnProperty(this.options, 'slides')) {
if (this.options.slides) {
delete this.options.slides
}
Expand All @@ -58,14 +60,18 @@ export default class VueComponent extends Vue {
if (this.config.slides != null && typeof this.config.slides[Symbol.iterator] === 'function') {
// Resolve relative URLs
for (const data of this.config.slides) {
if (hasOwnProperty(data, 'image')) {
if (!this.r.test(data.image))
data.image = fileApi.cleanURL(`${this.subfolder}/${data.image}`)
if (data.image) {
if (!this.absoluteUrl.test(data.image)) {
const exactUrl = await this.buildImageUrlFromUserPath(data.image)
data.image = exactUrl
}
}
if (hasOwnProperty(data, 'video')) {
if (!this.r.test(data.video))
data.video = fileApi.cleanURL(`${this.subfolder}/${data.video}`)
if (data.video) {
if (!this.absoluteUrl.test(data.video)) {
const exactUrl = await this.buildImageUrlFromUserPath(data.video)
data.video = exactUrl
}
}
this.slides.push(data)
Expand All @@ -74,6 +80,43 @@ export default class VueComponent extends Vue {
this.$emit('isLoaded')
}
/**
* User can provide a plain filename, a name with path,
* a path with "xxxx/../../xxxx", or even ""../*mode.png"
* Try to figure out what file they really want.
*/
private async buildImageUrlFromUserPath(path: string) {
// first get correct folder contents
let folder = this.subfolder
if (path.indexOf('/') > -1) folder += '/' + path.substring(0, path.lastIndexOf('/'))
const { files } = await this.fileApi.getDirectory(folder)
// now get search pattern
let pattern = path.indexOf('/') === -1 ? path : path.substring(path.lastIndexOf('/') + 1)
// do we have a match?
const match = findMatchingGlobInFiles(files, pattern)
if (match.length === 1) return this.fileApi.cleanURL(`${this.subfolder}/${match[0]}`)
if (!match.length) {
this.$store.commit('setStatus', {
type: Status.ERROR,
msg: `File cannot be loaded...`,
desc: 'Check filename and path: ' + pattern,
})
} else {
this.$store.commit('setStatus', {
type: Status.ERROR,
msg: `Multiple files match...`,
desc: 'Check filename and path: ' + pattern,
})
}
// still try to return something reasonable, even though it will fail
return this.fileApi.cleanURL(`${this.subfolder}/${path}`)
}
}
</script>

Expand Down
6 changes: 2 additions & 4 deletions src/js/DashboardDataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ export default class DashboardDataManager {
}

let myDataset = await this.datasets[config.dataset].dataset
let columns = Object.keys(myDataset)

let allRows = { ...myDataset }

// remove ignored columns
Expand Down Expand Up @@ -284,12 +282,12 @@ export default class DashboardDataManager {
thread.terminate()
if (e.data.error) {
console.log(e.data.error)
var msg = '' + e.data.error
// var msg = '' + e.data.error
//globalStore.commit('error', e.data.error)
globalStore.commit('setStatus', {
type: Status.ERROR,
msg: `File cannot be loaded...`,
desc: 'Please check if the file exists: ' + this.subfolder + '/' + config.dataset,
desc: 'Check filename and path: ' + this.subfolder + '/' + config.dataset,
})
reject()
}
Expand Down

0 comments on commit e216e4b

Please sign in to comment.