Skip to content

Commit

Permalink
Merge pull request simwrapper#137 from simwrapper/136-image-wildcards
Browse files Browse the repository at this point in the history
136-image-wildcards
  • Loading branch information
billyc committed Mar 29, 2022
2 parents e216e4b + 54b214a commit 80fa723
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
29 changes: 23 additions & 6 deletions src/charts/slideshow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'vueperslides/dist/vueperslides.css'
import { FileSystemConfig, Status } from '@/Globals'
import HTTPFileSystem from '@/js/HTTPFileSystem'
import SVNFileSystem from '@/js/HTTPFileSystem'
import { findMatchingGlobInFiles } from '@/js/util'
import { findMatchingGlobInFiles, arrayBufferToBase64 } from '@/js/util'
@Component({ components: { VueperSlides, VueperSlide } })
export default class VueComponent extends Vue {
Expand All @@ -50,13 +50,11 @@ export default class VueComponent extends Vue {
if (this.config != null) Object.assign(this.options, this.config)
// Delete slide property because this is only used in the loop
if (this.options.slides) {
delete this.options.slides
}
if (this.options.slides) delete this.options.slides
this.slides = []
// Check if defined and iterable
// TODO: throw
if (this.config.slides != null && typeof this.config.slides[Symbol.iterator] === 'function') {
// Resolve relative URLs
for (const data of this.config.slides) {
Expand All @@ -69,6 +67,9 @@ export default class VueComponent extends Vue {
if (data.video) {
if (!this.absoluteUrl.test(data.video)) {
// NO VIDEO for chrome-local-files-mode
if (this.fileSystemConfig.handle) return ''
const exactUrl = await this.buildImageUrlFromUserPath(data.video)
data.video = exactUrl
}
Expand Down Expand Up @@ -98,7 +99,23 @@ export default class VueComponent extends Vue {
// 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 === 1) {
if (!this.fileSystemConfig.handle) {
// Regular URL: return it
return this.fileApi.cleanURL(`${folder}/${match[0]}`)
} else {
// Chrome local files mode: read & generate base64 since regular URLs wont work
try {
const blob = await this.fileApi.getFileBlob(`${folder}/${match[0]}`)
const base64 = arrayBufferToBase64(await blob.arrayBuffer())
return `data:image/png;base64,${base64}`
// return `center / cover no-repeat url(data:image/png;base64,${base64})`
} catch (e) {
console.error(e)
}
}
}
if (!match.length) {
this.$store.commit('setStatus', {
Expand Down
15 changes: 12 additions & 3 deletions src/js/HTTPFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,21 @@ class SVNFileSystem {

let parts = stillScaryPath.split('/').filter(p => !!p) // split and remove blanks

// Normalize directory / get rid of '..' sections
function eatDots(parts: string[]): string[] {
const dotdot = parts.indexOf('..')
if (dotdot <= 0) return parts
const spliced = parts.filter((part: string, i) => i !== dotdot - 1 && i !== dotdot)
return eatDots(spliced)
}

const cleanDirParts: string[] = eatDots(parts)

let currentDir = this.fsHandle as any

// iterate thru the tree, top-down:
if (parts.length) {
for (const subfolder of parts) {
console.log('searching for:', subfolder)
if (cleanDirParts.length) {
for (const subfolder of cleanDirParts) {
let found = false
for await (let [name, handle] of currentDir) {
if (name === subfolder) {
Expand Down

0 comments on commit 80fa723

Please sign in to comment.