mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-04-05 17:15:40 +00:00
fix file extensions
This commit is contained in:
parent
e55833eafd
commit
9c461a9bdb
@ -1,6 +1,7 @@
|
||||
export default {
|
||||
url: { primary: true, type: 'string', uri: { allowRelative: true } },
|
||||
name: { type: 'string' },
|
||||
extension: { type: 'string', allow: [null, ''] },
|
||||
type: { type: 'string' },
|
||||
duration: { type: 'number', allow: [null] },
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
|
||||
@ -28,6 +28,7 @@ export interface AddAttachmentOpts {
|
||||
export interface FileInput {
|
||||
upload?: Promise<FileUpload>
|
||||
name: string
|
||||
extension?: string | null
|
||||
type: string
|
||||
duration?: number | null
|
||||
}
|
||||
@ -35,6 +36,7 @@ export interface FileInput {
|
||||
export interface File {
|
||||
url: string
|
||||
name: string
|
||||
extension?: string | null
|
||||
type: string
|
||||
duration?: number | null
|
||||
}
|
||||
@ -145,8 +147,15 @@ export const attachments = (config: S3Config) => {
|
||||
uniqueFilename,
|
||||
})
|
||||
|
||||
const { name, type, duration } = fileInput
|
||||
const file = { url, name, type, ...(duration != null && { duration }), ...fileAttributes }
|
||||
const { name, extension, type, duration } = fileInput
|
||||
const file = {
|
||||
url,
|
||||
name,
|
||||
...(extension && { extension }),
|
||||
type,
|
||||
...(duration != null && { duration }),
|
||||
...fileAttributes,
|
||||
}
|
||||
// const mimeType = uploadFile.mimetype.split('/')[0]
|
||||
// const nodeType = `Mime${mimeType.replace(/^./, mimeType[0].toUpperCase())}`
|
||||
// CREATE (file:${['File', nodeType].filter(Boolean).join(':')})
|
||||
|
||||
@ -281,6 +281,7 @@ export default {
|
||||
}),
|
||||
},
|
||||
File: {
|
||||
extension: (parent: { extension?: string | null }) => parent.extension ?? null,
|
||||
duration: (parent: { duration?: number | null }) => parent.duration ?? null,
|
||||
},
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
type File {
|
||||
url: ID!
|
||||
name: String
|
||||
extension: String
|
||||
type: String
|
||||
duration: Float
|
||||
# size: Int
|
||||
@ -12,6 +13,7 @@ type File {
|
||||
input FileInput {
|
||||
upload: Upload
|
||||
name: String
|
||||
extension: String
|
||||
type: String
|
||||
duration: Float
|
||||
}
|
||||
|
||||
@ -712,7 +712,7 @@ describe('Chat.vue', () => {
|
||||
expect.objectContaining({
|
||||
variables: expect.objectContaining({
|
||||
files: expect.arrayContaining([
|
||||
expect.objectContaining({ name: 'test', type: 'text/plain' }),
|
||||
expect.objectContaining({ name: 'test', extension: 'txt', type: 'text/plain' }),
|
||||
]),
|
||||
}),
|
||||
}),
|
||||
|
||||
@ -314,24 +314,12 @@ export default {
|
||||
commitUnreadRoomCount: 'chat/UPDATE_ROOM_COUNT',
|
||||
}),
|
||||
|
||||
lastMessageFiles(files) {
|
||||
if (!files?.length) return undefined
|
||||
return files.map((f) => {
|
||||
if (f.extension) return f
|
||||
const dotIndex = f.name?.lastIndexOf('.')
|
||||
const ext = dotIndex > 0 ? f.name.substring(dotIndex + 1) : f.type?.split('/').pop()
|
||||
const name = dotIndex > 0 ? f.name.substring(0, dotIndex) : f.name
|
||||
return { ...f, name, extension: ext }
|
||||
})
|
||||
},
|
||||
|
||||
lastMessageContent(content, files) {
|
||||
const text = (content || '').trim()
|
||||
if (text) return text.substring(0, 30)
|
||||
if (!files?.length) return ''
|
||||
if (files[0].type?.startsWith('audio/') || files[0].audio) return ''
|
||||
const f = files[0]
|
||||
const isAudio = f.type?.startsWith('audio/') || f.audio
|
||||
if (isAudio) return ''
|
||||
const name = f.extension ? `${f.name}.${f.extension}` : f.name || ''
|
||||
return `\uD83D\uDCCE ${name}`
|
||||
},
|
||||
@ -657,7 +645,7 @@ export default {
|
||||
changedRoom.lastMessage = {
|
||||
...msg,
|
||||
content: this.lastMessageContent(msg.content, msg.files),
|
||||
files: this.lastMessageFiles(msg.files),
|
||||
files: msg.files,
|
||||
}
|
||||
changedRoom.lastMessageAt = msg.date
|
||||
changedRoom.index = new Date().toISOString()
|
||||
@ -730,11 +718,11 @@ export default {
|
||||
? files.map((file) => ({
|
||||
upload: new File(
|
||||
[file.blob],
|
||||
// Captured audio already has the right extension in the name
|
||||
file.extension ? `${file.name}.${file.extension}` : file.name,
|
||||
{ type: file.type },
|
||||
),
|
||||
name: file.name,
|
||||
extension: file.extension || undefined,
|
||||
type: file.type,
|
||||
...(file.duration != null && { duration: file.duration }),
|
||||
}))
|
||||
@ -766,7 +754,7 @@ export default {
|
||||
if (roomIndex !== -1) {
|
||||
const changedRoom = { ...this.rooms[roomIndex] }
|
||||
changedRoom.lastMessage.content = this.lastMessageContent(content, files)
|
||||
changedRoom.lastMessage.files = this.lastMessageFiles(files)
|
||||
changedRoom.lastMessage.files = files
|
||||
changedRoom.index = new Date().toISOString()
|
||||
this.rooms = [changedRoom, ...this.rooms.filter((r) => r.id !== roomId)]
|
||||
this.$nextTick(() => {
|
||||
@ -852,7 +840,7 @@ export default {
|
||||
? {
|
||||
...room.lastMessage,
|
||||
content: this.lastMessageContent(room.lastMessage?.content, room.lastMessage?.files),
|
||||
files: this.lastMessageFiles(room.lastMessage?.files),
|
||||
files: room.lastMessage?.files,
|
||||
}
|
||||
: { content: '' },
|
||||
users: room.users.map((u) => {
|
||||
|
||||
@ -24,6 +24,7 @@ export const createMessageMutation = () => {
|
||||
files {
|
||||
url
|
||||
name
|
||||
extension
|
||||
#size
|
||||
type
|
||||
duration
|
||||
@ -64,6 +65,7 @@ export const messageQuery = () => {
|
||||
files {
|
||||
url
|
||||
name
|
||||
extension
|
||||
#size
|
||||
type
|
||||
#audio
|
||||
@ -99,6 +101,7 @@ export const chatMessageAdded = () => {
|
||||
files {
|
||||
url
|
||||
name
|
||||
extension
|
||||
#size
|
||||
type
|
||||
#audio
|
||||
|
||||
@ -69,6 +69,7 @@ export const roomQuery = () => gql`
|
||||
files {
|
||||
url
|
||||
name
|
||||
extension
|
||||
type
|
||||
duration
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user