generated from Nodarx/template
Add office editor provider
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
import { createFetchWrapper } from '@KTXC'
|
||||
|
||||
export interface LaunchSession {
|
||||
actionUrl: string
|
||||
accessToken: string
|
||||
accessTokenTtl: number
|
||||
officeOrigin: string
|
||||
mode: 'view'
|
||||
}
|
||||
|
||||
const api = createFetchWrapper()
|
||||
export const launch = (resource: string): Promise<LaunchSession> => api.post('/m/service_wopi/sessions', { resource })
|
||||
|
||||
export function validateSession(session: LaunchSession): void {
|
||||
const action = new URL(session.actionUrl)
|
||||
if (action.protocol !== 'https:' || action.origin !== session.officeOrigin || action.username || action.password
|
||||
|| session.mode !== 'view' || !/^[a-f0-9]{64}$/.test(session.accessToken)
|
||||
|| !Number.isSafeInteger(session.accessTokenTtl) || session.accessTokenTtl <= Date.now()) {
|
||||
throw new Error('Invalid office session.')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user