mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-30 03:39:39 +02:00
* UBERF-11387 Preview service Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * code review fixes Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * optimize build Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * use base preview image Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * free some disk space in github runner Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * fix: try to clean builder cache Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * fix: update sharp version for preview Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * some cache fixes Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> --------- Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
//
|
|
// Copyright © 2024 Hardcore Engineering Inc.
|
|
//
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License. You may
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
//
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import { type Blob, type BlobMetadata, type Ref } from '@hcengineering/core'
|
|
import { getMetadata } from '@hcengineering/platform'
|
|
import presentation, { getImageSize, getPreviewMetadata } from '@hcengineering/presentation'
|
|
|
|
export async function blobPreviewMetadata (blob: Ref<Blob>): Promise<BlobMetadata | undefined> {
|
|
const workspace = getMetadata(presentation.metadata.WorkspaceUuid) ?? ''
|
|
return await getPreviewMetadata(workspace, blob)
|
|
}
|
|
|
|
export async function blobImageMetadata (file: File, blob: Ref<Blob>): Promise<BlobMetadata | undefined> {
|
|
if (file.size === 0) {
|
|
return undefined
|
|
}
|
|
|
|
const size = await getImageSize(file)
|
|
|
|
return {
|
|
originalHeight: size.height,
|
|
originalWidth: size.width,
|
|
pixelRatio: size.pixelRatio
|
|
}
|
|
}
|
|
|
|
export async function blobVideoMetadata (file: File, blob: Ref<Blob>): Promise<BlobMetadata | undefined> {
|
|
if (file.size === 0) {
|
|
return undefined
|
|
}
|
|
|
|
const size = await getVideoSize(file)
|
|
|
|
if (size === undefined) {
|
|
return undefined
|
|
}
|
|
|
|
return {
|
|
originalHeight: size.height,
|
|
originalWidth: size.width
|
|
}
|
|
}
|
|
|
|
async function getVideoSize (file: File): Promise<{ width: number, height: number } | undefined> {
|
|
const promise = new Promise<{ width: number, height: number }>((resolve, reject) => {
|
|
const element = document.createElement('video')
|
|
|
|
const src = URL.createObjectURL(file)
|
|
|
|
element.onloadedmetadata = () => {
|
|
const height = element.videoHeight
|
|
const width = element.videoWidth
|
|
|
|
URL.revokeObjectURL(src)
|
|
resolve({ height, width })
|
|
}
|
|
|
|
element.onerror = reject
|
|
element.src = src
|
|
})
|
|
|
|
return await promise
|
|
}
|