fix: support uploading files with non-Latin characters in filename
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import { simplifyUrl } from '@/lib/url'
|
import { simplifyUrl } from '@/lib/url'
|
||||||
import { TDraftEvent, TMediaUploadServiceConfig } from '@/types'
|
import { TDraftEvent, TMediaUploadServiceConfig } from '@/types'
|
||||||
import { BlossomClient } from 'blossom-client-sdk'
|
import { BlossomClient } from 'blossom-client-sdk'
|
||||||
import dayjs from 'dayjs'
|
|
||||||
import { kinds } from 'nostr-tools'
|
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import client from './client.service'
|
import client from './client.service'
|
||||||
import storage from './local-storage.service'
|
import storage from './local-storage.service'
|
||||||
@@ -58,7 +56,7 @@ class MediaUploadService {
|
|||||||
const [mainServer, ...mirrorServers] = servers
|
const [mainServer, ...mirrorServers] = servers
|
||||||
|
|
||||||
const auth = await BlossomClient.createUploadAuth(signer, file, {
|
const auth = await BlossomClient.createUploadAuth(signer, file, {
|
||||||
message: `Uploading ${file.name}`
|
message: 'Uploading media file'
|
||||||
})
|
})
|
||||||
|
|
||||||
// first upload blob to main server
|
// first upload blob to main server
|
||||||
@@ -101,7 +99,7 @@ class MediaUploadService {
|
|||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
|
|
||||||
const auth = await this.signHttpAuth(uploadUrl, 'POST')
|
const auth = await client.signHttpAuth(uploadUrl, 'POST', 'Uploading media file')
|
||||||
const response = await fetch(uploadUrl, {
|
const response = await fetch(uploadUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
@@ -127,22 +125,6 @@ class MediaUploadService {
|
|||||||
getImetaTagByUrl(url: string) {
|
getImetaTagByUrl(url: string) {
|
||||||
return this.imetaTagMap.get(url)
|
return this.imetaTagMap.get(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
async signHttpAuth(url: string, method: string) {
|
|
||||||
if (!client.signer) {
|
|
||||||
throw new Error('No signer found')
|
|
||||||
}
|
|
||||||
const event = await client.signer.signEvent({
|
|
||||||
content: '',
|
|
||||||
kind: kinds.HTTPAuth,
|
|
||||||
created_at: dayjs().unix(),
|
|
||||||
tags: [
|
|
||||||
['u', url],
|
|
||||||
['method', method]
|
|
||||||
]
|
|
||||||
})
|
|
||||||
return 'Nostr ' + btoa(JSON.stringify(event))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = new MediaUploadService()
|
const instance = new MediaUploadService()
|
||||||
|
|||||||
Reference in New Issue
Block a user