Skip to content

Commit

Permalink
fix: rebuild src of local media files only
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Apr 15, 2024
1 parent 2afe54d commit 0e453d1
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
useAppDefaults,
useAppFileHandling,
useClientService,
useAppsStore
useAppsStore,
useConfigStore
} from '@ownclouders/web-pkg'
import { Resource } from '@ownclouders/web-client/src'
import Reveal from 'reveal.js'
Expand All @@ -45,11 +46,13 @@ const { getUrlForResource, revokeUrl } = useAppFileHandling({
clientService: useClientService
})
const appsStore = useAppsStore()
const { serverUrl } = useConfigStore()
const isDarkMode = ref(themeStore.currentTheme.isDark)
const slideContainer = ref<HTMLElement | undefined>()
const mediaUrls = ref([])
const mediaBasePath = `${serverUrl}local/`
const dataSeparator = '\r?\n---\r?\n'
const dataSeparatorVertical = '\r?\n--\r?\n'
Expand Down Expand Up @@ -82,16 +85,20 @@ onMounted(async () => {
progress: true,
history: true,
center: true,
controlsLayout: 'edges'
controlsLayout: 'edges',
markdown: {
baseUrl: mediaBasePath
}
})
reveal.on('ready', async () => {
const imgElements = unref(slideContainer).getElementsByTagName('img')
await updateImageUrls(imgElements)
const localImgElements = filterLocalImgElements(imgElements)
await updateImageUrls(localImgElements)
})
})
onBeforeUnmount(() => {
Object.values(unref(mediaUrls)).forEach((url) => {
unref(mediaUrls).forEach((url) => {
revokeUrl(url)
})
})
Expand All @@ -111,8 +118,19 @@ const mediaFiles = computed<Resource[]>(() => {
})
// METHODS
async function updateImageUrls(imgElements: HTMLCollectionOf<HTMLImageElement>) {
function filterLocalImgElements(
imgElements: HTMLCollectionOf<HTMLImageElement>
): HTMLImageElement[] {
const localImgElements: HTMLImageElement[] = []
for (const el of imgElements) {
if (el.src.startsWith(mediaBasePath)) {
localImgElements.push(el)
}
}
return localImgElements
}
async function updateImageUrls(localImgElements: HTMLImageElement[]) {
for (const el of localImgElements) {
const src = el.src.split('/').pop()
const blobUrl = await parseImageUrl(src)
el.src = blobUrl
Expand All @@ -123,6 +141,8 @@ async function parseImageUrl(name: string) {
for (const file of unref(mediaFiles)) {
if (file.name === name) {
const url = await getUrlForResource(unref(currentFileContext).space, file)
// reload the active files
await loadFolderForFileContext(unref(currentFileContext))
return getBlobUrl(url)
}
}
Expand Down

0 comments on commit 0e453d1

Please sign in to comment.