Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extensions to announce contentType to AppWrapper, make saving images possible #11607

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions packages/web-pkg/src/components/AppTemplates/AppWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
computed,
onMounted
} from 'vue'
import toNumber from 'lodash-es/toNumber'
import { DateTime } from 'luxon'
import { dirname } from 'path'
import { useTask } from 'vue-concurrency'
import { useGettext } from 'vue3-gettext'
import { onBeforeRouteLeave, useRouter } from 'vue-router'
Expand All @@ -46,54 +48,50 @@ import ErrorScreen from './PartialViews/ErrorScreen.vue'
import LoadingScreen from './PartialViews/LoadingScreen.vue'
import FileSideBar from '../SideBar/FileSideBar.vue'
import {
UrlForResourceOptions,
Action,
FileAction,
FileActionOptions,
FileContentOptions,
Key,
Modifier,
queryItemAsString,
UrlForResourceOptions,
useAppDefaults,
useClientService,
useRoute,
useRouteParam,
useRouteQuery,
useSelectedResources,
useSideBar,
useModals,
useMessages,
useSpacesStore,
useAppMeta,
useAppsStore,
useClientService,
useConfigStore,
useResourcesStore,
FileContentOptions,
useFileActionsCopyPermanentLink,
useFileActionsDownloadFile,
useFileActionsSaveAs,
useFileActionsShowDetails,
useFileActionsShowShares,
FileActionOptions,
FileAction,
useLoadingService,
useFileActionsSaveAs
} from '../../composables'
import {
Action,
Modifier,
Key,
useAppMeta,
useGetResourceContext,
useKeyboardActions
useKeyboardActions,
useLoadingService,
useMessages,
useModals,
useResourcesStore,
useRoute,
useRouteParam,
useRouteQuery,
useSelectedResources,
useSideBar,
useSpacesStore
} from '../../composables'
import { useFileActionsOpenWithApp } from '../../composables/actions/files/useFileActionsOpenWithApp'
import {
Resource,
SpaceResource,
call,
HttpError,
isPersonalSpaceResource,
isProjectSpaceResource,
isShareSpaceResource
isShareSpaceResource,
Resource,
SpaceResource
} from '@ownclouders/web-client'
import { DavPermission } from '@ownclouders/web-client/webdav'
import { HttpError } from '@ownclouders/web-client'
import { dirname } from 'path'
import { useFileActionsOpenWithApp } from '../../composables/actions/files/useFileActionsOpenWithApp'
import { UnsavedChangesModal } from '../Modals'
import { formatFileSize } from '../../helpers'
import toNumber from 'lodash-es/toNumber'

export default defineComponent({
name: 'AppWrapper',
Expand Down Expand Up @@ -130,6 +128,10 @@ export default defineComponent({
disableAutoSave: {
type: Boolean,
default: false
},
contentType: {
type: String,
default: 'text/plain'
}
},
setup(props) {
Expand Down Expand Up @@ -393,10 +395,19 @@ export default defineComponent({

const saveFileTask = useTask(function* () {
const newContent = unref(currentContent)

const headers =
props.contentType === 'image'
? {
'Content-Type': 'application/offset+octet-stream'
}
: {}

try {
const putFileContentsResponse = yield putFileContents(currentFileContext, {
content: newContent,
previousEntityTag: unref(currentETag)
previousEntityTag: unref(currentETag),
headers
})
serverContent.value = newContent
currentETag.value = putFileContentsResponse.etag
Expand Down Expand Up @@ -468,15 +479,12 @@ export default defineComponent({
}
const editorOptions = configStore.options.editor
if (editorOptions.autosaveEnabled && !props.disableAutoSave) {
autosaveIntervalId = setInterval(
async () => {
if (isDirty.value) {
await save()
autosavePopup()
}
},
(editorOptions.autosaveInterval || 120) * 1000
)
autosaveIntervalId = setInterval(async () => {
if (isDirty.value) {
await save()
autosavePopup()
}
}, (editorOptions.autosaveInterval || 120) * 1000)
}
})
onBeforeUnmount(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function AppWrapperRoute(
fileContentOptions?: FileContentOptions
importResourceWithExtension?: (resource: Resource) => string
disableAutoSave?: boolean
contentType?: string
}
) {
return defineComponent({
Expand Down