release #111
@ -410,7 +410,7 @@ export const CreatePage = () => {
|
|||||||
type: 'application/sigit'
|
type: 'application/sigit'
|
||||||
})
|
})
|
||||||
|
|
||||||
const fileUrl = await uploadToFileStorage(file, nostrController)
|
const fileUrl = await uploadToFileStorage(file)
|
||||||
.then((url) => {
|
.then((url) => {
|
||||||
toast.success('files.zip uploaded to file storage')
|
toast.success('files.zip uploaded to file storage')
|
||||||
return url
|
return url
|
||||||
|
@ -2,6 +2,7 @@ import axios from 'axios'
|
|||||||
import {
|
import {
|
||||||
Event,
|
Event,
|
||||||
EventTemplate,
|
EventTemplate,
|
||||||
|
finalizeEvent,
|
||||||
generateSecretKey,
|
generateSecretKey,
|
||||||
getPublicKey,
|
getPublicKey,
|
||||||
nip04,
|
nip04,
|
||||||
@ -14,6 +15,7 @@ import store from '../store/store'
|
|||||||
import { CreateSignatureEventContent, Meta } from '../types'
|
import { CreateSignatureEventContent, Meta } from '../types'
|
||||||
import { hexToNpub, now } from './nostr'
|
import { hexToNpub, now } from './nostr'
|
||||||
import { parseJson } from './string'
|
import { parseJson } from './string'
|
||||||
|
import { hexToBytes } from '@noble/hashes/utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads a file to a file storage service.
|
* Uploads a file to a file storage service.
|
||||||
@ -21,10 +23,7 @@ import { parseJson } from './string'
|
|||||||
* @param nostrController The NostrController instance for handling authentication.
|
* @param nostrController The NostrController instance for handling authentication.
|
||||||
* @returns The URL of the uploaded file.
|
* @returns The URL of the uploaded file.
|
||||||
*/
|
*/
|
||||||
export const uploadToFileStorage = async (
|
export const uploadToFileStorage = async (file: File) => {
|
||||||
file: File,
|
|
||||||
nostrController: NostrController
|
|
||||||
) => {
|
|
||||||
// Define event metadata for authorization
|
// Define event metadata for authorization
|
||||||
const event: EventTemplate = {
|
const event: EventTemplate = {
|
||||||
kind: 24242,
|
kind: 24242,
|
||||||
@ -38,8 +37,15 @@ export const uploadToFileStorage = async (
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign the authorization event using the NostrController
|
const key = store.getState().userAppData?.keyPair?.private
|
||||||
const authEvent = await nostrController.signEvent(event)
|
if (!key) {
|
||||||
|
throw new Error(
|
||||||
|
'Key to interact with blossom server is not defined in user app data'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign the authorization event using the dedicated key stored in user app data
|
||||||
|
const authEvent = finalizeEvent(event, hexToBytes(key))
|
||||||
|
|
||||||
// URL of the file storage service
|
// URL of the file storage service
|
||||||
const FILE_STORAGE_URL = 'https://blossom.sigit.io' // REFACTOR: should be an env
|
const FILE_STORAGE_URL = 'https://blossom.sigit.io' // REFACTOR: should be an env
|
||||||
|
Loading…
Reference in New Issue
Block a user