mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Using proper image transformation
This commit is contained in:
@ -128,8 +128,8 @@ const ComposeEditAttachmentImage: React.FC<Props> = ({ index }) => {
|
||||
height: imageDimensionis.height
|
||||
}}
|
||||
source={{
|
||||
uri: theAttachmentLocal?.path
|
||||
? `file://${theAttachmentLocal?.path}`
|
||||
uri: theAttachmentLocal?.uri
|
||||
? theAttachmentLocal.uri
|
||||
: theAttachmentRemote?.preview_url
|
||||
}}
|
||||
/>
|
||||
|
@ -34,7 +34,7 @@ const ComposeEditAttachmentRoot: React.FC<Props> = ({ index }) => {
|
||||
video={
|
||||
video.local
|
||||
? ({
|
||||
url: `file://${video.local.path}`,
|
||||
url: video.local.uri,
|
||||
preview_url: video.local.local_thumbnail,
|
||||
blurhash: video.remote?.blurhash
|
||||
} as Mastodon.AttachmentVideo)
|
||||
|
@ -22,28 +22,25 @@ export const uploadAttachment = async ({
|
||||
media
|
||||
}: {
|
||||
composeDispatch: Dispatch<ComposeAction>
|
||||
media: Pick<ImageOrVideo, 'path' | 'mime' | 'width' | 'height'>
|
||||
media: { uri: string } & Pick<ImageOrVideo, 'mime' | 'width' | 'height'>
|
||||
}) => {
|
||||
const hash = await Crypto.digestStringAsync(
|
||||
Crypto.CryptoDigestAlgorithm.SHA256,
|
||||
media.path + Math.random()
|
||||
media.uri + Math.random()
|
||||
)
|
||||
let attachmentType: string
|
||||
|
||||
switch (media.mime.split('/')[0]) {
|
||||
case 'image':
|
||||
attachmentType = `image/${media.path.split('.')[1]}`
|
||||
composeDispatch({
|
||||
type: 'attachment/upload/start',
|
||||
payload: {
|
||||
local: { ...media, type: 'image', local_thumbnail: media.path, hash },
|
||||
local: { ...media, type: 'image', local_thumbnail: media.uri, hash },
|
||||
uploading: true
|
||||
}
|
||||
})
|
||||
break
|
||||
case 'video':
|
||||
attachmentType = `video/${media.path.split('.')[1]}`
|
||||
VideoThumbnails.getThumbnailAsync(media.path)
|
||||
VideoThumbnails.getThumbnailAsync(media.uri)
|
||||
.then(({ uri, width, height }) =>
|
||||
composeDispatch({
|
||||
type: 'attachment/upload/start',
|
||||
@ -71,7 +68,6 @@ export const uploadAttachment = async ({
|
||||
)
|
||||
break
|
||||
default:
|
||||
attachmentType = 'unknown'
|
||||
composeDispatch({
|
||||
type: 'attachment/upload/start',
|
||||
payload: {
|
||||
@ -105,9 +101,9 @@ export const uploadAttachment = async ({
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('file', {
|
||||
uri: `file://${media.path}`,
|
||||
name: attachmentType,
|
||||
type: attachmentType
|
||||
uri: media.uri,
|
||||
name: media.uri.match(new RegExp(/.*\/(.*)/))?.[1] || 'file.jpg',
|
||||
type: media.mime
|
||||
} as any)
|
||||
|
||||
return apiInstance<Mastodon.Attachment>({
|
||||
|
@ -90,7 +90,7 @@ const ComposeTextInput: React.FC = () => {
|
||||
uploadAttachment({
|
||||
composeDispatch,
|
||||
media: {
|
||||
path: file.uri,
|
||||
uri: file.uri,
|
||||
mime: file.type,
|
||||
width: 100,
|
||||
height: 100
|
||||
|
@ -58,7 +58,7 @@ const composeReducer = (
|
||||
attachments: {
|
||||
...state.attachments,
|
||||
uploads: state.attachments.uploads.map(upload =>
|
||||
upload.local?.path === action.payload.local?.path
|
||||
upload.local?.uri === action.payload.local?.uri
|
||||
? { ...upload, remote: action.payload.remote, uploading: false }
|
||||
: upload
|
||||
)
|
||||
|
12
src/screens/Compose/utils/types.d.ts
vendored
12
src/screens/Compose/utils/types.d.ts
vendored
@ -2,11 +2,11 @@ import { ImageOrVideo } from 'react-native-image-crop-picker'
|
||||
|
||||
export type ExtendedAttachment = {
|
||||
remote?: Mastodon.Attachment
|
||||
local?: Pick<ImageOrVideo, 'path' | 'width' | 'height' | 'mime'> & {
|
||||
type: 'image' | 'video' | 'unknown'
|
||||
local_thumbnail?: string
|
||||
hash?: string
|
||||
}
|
||||
local?: { uri: string } & Pick<ImageOrVideo, 'width' | 'height' | 'mime'> & {
|
||||
type: 'image' | 'video' | 'unknown'
|
||||
local_thumbnail?: string
|
||||
hash?: string
|
||||
}
|
||||
uploading?: boolean
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ export type ComposeAction =
|
||||
type: 'attachment/upload/end'
|
||||
payload: {
|
||||
remote: Mastodon.Attachment
|
||||
local: Pick<ImageOrVideo, 'path' | 'width' | 'height' | 'mime'>
|
||||
local: { uri: string } & Pick<ImageOrVideo, 'width' | 'height' | 'mime'>
|
||||
}
|
||||
}
|
||||
| {
|
||||
|
Reference in New Issue
Block a user