refactor(upload): [WIP] try out Server endpoints, axios
This commit is contained in:
parent
fe6647e0fb
commit
54654c4e13
|
@ -9,6 +9,7 @@ import { useI18n } from 'vue-i18n'
|
|||
import { useStore } from '~/store'
|
||||
|
||||
import axios from 'axios'
|
||||
import { type paths, type schemas, type operations, type components } from '~/generated/types.ts'
|
||||
|
||||
import UploadMetadataForm from '~/components/channels/UploadMetadataForm.vue'
|
||||
import FileUploadWidget from '~/components/library/FileUploadWidget.vue'
|
||||
|
@ -17,6 +18,13 @@ import AlbumSelect from '~/components/channels/AlbumSelect.vue'
|
|||
|
||||
import useErrorHandler from '~/composables/useErrorHandler'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
interface Events {
|
||||
(e: 'status', status: UploadStatus): void
|
||||
}
|
||||
|
@ -342,14 +350,28 @@ const publish = async () => {
|
|||
|
||||
errors.value = []
|
||||
|
||||
|
||||
console.log("first, let's try to create an empty channel...")
|
||||
createEmptyChannel();
|
||||
|
||||
try {
|
||||
// Post list of uuids of uploadedFiles to axios action:publish
|
||||
await axios.put('uploads/action/', {
|
||||
|
||||
/* { import_status: components["schemas"]["ImportStatusEnum"];
|
||||
audio_file: string;} */
|
||||
|
||||
const theUpdate : components['schemas']['PatchedUploadForOwnerRequest'] = {
|
||||
import_status: 'pending',
|
||||
}
|
||||
|
||||
await axios.post('uploads/action/', {
|
||||
action: 'publish',
|
||||
objects: uploadedFiles.value.map((file) => file.response?.uuid)
|
||||
} satisfies paths['/api/v2/uploads/action/']['post']['requestBody']['content']['application/json'],
|
||||
{
|
||||
headers: { 'Authorization': `Bearer ${store.state.auth.oauth}` }
|
||||
})
|
||||
|
||||
console.log("starting posting to axios action:publish...")
|
||||
|
||||
console.log("Channels Store Before: ", store.state.channels)
|
||||
|
||||
|
@ -375,6 +397,95 @@ const publish = async () => {
|
|||
defineExpose({
|
||||
publish
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Api Calls
|
||||
|
||||
// Create a new channel
|
||||
/*
|
||||
"/api/v2/channels/": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get: operations["get_channels_2"]; //!
|
||||
put?: never;
|
||||
post: operations["create_channel_2"]; //!
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
|
||||
create_channel_2: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["ChannelCreateRequest"]; !
|
||||
"application/x-www-form-urlencoded": components["schemas"]["ChannelCreateRequest"];
|
||||
"multipart/form-data": components["schemas"]["ChannelCreateRequest"];
|
||||
"application/activity+json": components["schemas"]["ChannelCreateRequest"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
201: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ChannelCreate"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
ChannelCreateRequest: {
|
||||
cover?: string | null;
|
||||
name: string; !!!
|
||||
username: string; !!!
|
||||
description: components["schemas"]["ContentRequest"] | null; null
|
||||
tags: string[]; []
|
||||
content_category: components["schemas"]["ContentCategoryEnum"]; 'music'
|
||||
metadata?: { //undefined
|
||||
[key: string]: unknown;
|
||||
};
|
||||
};
|
||||
*/
|
||||
|
||||
const emptyChannelCreateRequest:schemas['ChannelCreateRequest'] = {
|
||||
name: 'empty channel',
|
||||
username: store.state.auth.username,
|
||||
description: null,
|
||||
tags: [],
|
||||
content_category: 'music',
|
||||
}
|
||||
|
||||
//json
|
||||
const emptyCreate_channel_2RequestBodyContentJson:operations['create_channel_2']['requestBody']['content']['application/json'] =
|
||||
emptyChannelCreateRequest
|
||||
|
||||
//post
|
||||
const createEmptyChannel = async () => {
|
||||
try {
|
||||
const response = await axios.post('channels/', emptyCreate_channel_2RequestBodyContentJson)
|
||||
console.log("Created Channel: ", response.data)
|
||||
} catch (error) {
|
||||
errors.value = (error as BackendError).backendErrors
|
||||
console.log("Error:", error)
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
Loading…
Reference in New Issue