Skip to content

Commit a3727ee

Browse files
authored
Merge pull request #1 from omgate234/feat/image-audio-ondemand-url
feat: on demand url
2 parents e14927d + e913bb1 commit a3727ee

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

src/components/chat/ChatInterface.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
:collection-videos="activeCollectionVideos"
111111
:collection-audios="activeCollectionAudios"
112112
:collection-images="activeCollectionImages"
113+
:get-image-url="generateImageUrl"
114+
:get-audio-url="generateAudioUrl"
113115
@video-click="handleVideoClick"
114116
@delete-video="promptDeleteVideo"
115117
@delete-audio="promptDeleteAudio"
@@ -436,6 +438,7 @@ const {
436438
conversations,
437439
loadSession,
438440
generateImageUrl,
441+
generateAudioUrl,
439442
uploadMedia,
440443
createCollection,
441444
deleteCollection,

src/components/chat/CollectionView.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
<VideoList
9494
v-if="videos.length > 0"
9595
:asset-results="filteredAssets"
96+
:get-image-url="getImageUrl"
97+
:get-audio-url="getAudioUrl"
9698
@video-click="handleVideoClick"
9799
@delete-video="emit('delete-video', $event)"
98100
@delete-image="emit('delete-image', $event)"
@@ -165,6 +167,12 @@ const props = defineProps({
165167
type: Array,
166168
default: null,
167169
},
170+
getAudioUrl: {
171+
type: Function,
172+
},
173+
getImageUrl: {
174+
type: Function,
175+
},
168176
});
169177
170178
const mediaTypes = [
@@ -252,6 +260,8 @@ const emit = defineEmits([
252260
"delete-video",
253261
"delete-audio",
254262
"delete-image",
263+
"get-image-url",
264+
"get-audio-url",
255265
]);
256266
257267
const videos = computed(() => {

src/components/collection/AudioCard.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
class="thumbnail vdb-c-absolute vdb-c-bottom-0 vdb-c-left-0 vdb-c-right-0 vdb-c-top-0 vdb-c-rounded-lg vdb-c-bg-cover vdb-c-bg-center vdb-c-bg-no-repeat vdb-c-shadow-1"
2626
/>
2727
<div
28+
v-if="url"
2829
class="center-button transparent-button vdb-c-absolute vdb-c-left-1/2 vdb-c-top-1/2 vdb-c-flex vdb-c-h-48 vdb-c-w-48 -vdb-c-translate-x-1/2 -vdb-c-translate-y-1/2 vdb-c-transform vdb-c-items-center vdb-c-justify-center vdb-c-rounded-full lg:vdb-c-h-56 lg:vdb-c-w-56"
29-
@click="playAudio(item.url)"
30+
@click="playAudio(url)"
3031
>
3132
<PlayIcon class="vdb-c-h-20 vdb-c-w-20" />
3233
</div>
@@ -63,7 +64,7 @@
6364
</template>
6465

6566
<script setup>
66-
import { ref } from "vue";
67+
import { onMounted, ref } from "vue";
6768
import DeleteIcon from "../icons/Delete2.vue";
6869
import PlayIcon from "../icons/play.vue";
6970
@@ -72,6 +73,7 @@ import NotificationCenter from "../chat/elements/NotificationCenter.vue";
7273
import CopyIcon from "../icons/CopyIcon.vue";
7374
7475
const hoveredDeleteIcon = ref(null);
76+
const url = ref(null);
7577
7678
const props = defineProps({
7779
item: {
@@ -86,6 +88,19 @@ const props = defineProps({
8688
type: String,
8789
default: "default",
8890
},
91+
getAudioUrl: {
92+
type: Function,
93+
},
94+
});
95+
96+
onMounted(async () => {
97+
if (props.getAudioUrl) {
98+
const audioUrl = await props.getAudioUrl(
99+
props.item.collection_id,
100+
props.item.id,
101+
);
102+
url.value = audioUrl.url;
103+
}
89104
});
90105
91106
const notificationCenterRef = ref(null);

src/components/collection/ImageCard.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
class="vid-pb vdb-c-relative vdb-c-overflow-hidden vdb-c-rounded-[7px]"
2323
>
2424
<div
25-
v-if="item.url"
25+
v-if="url"
2626
class="thumbnail vdb-c-absolute vdb-c-bottom-0 vdb-c-left-0 vdb-c-right-0 vdb-c-top-0 vdb-c-h-106 vdb-c-rounded-lg vdb-c-bg-cover vdb-c-bg-center vdb-c-bg-no-repeat vdb-c-shadow-1"
2727
:style="{
28-
backgroundImage: `url('${item.url}')`,
28+
backgroundImage: `url('${url}')`,
2929
backgroundColor: 'transparent',
3030
}"
3131
></div>
@@ -65,13 +65,13 @@
6565
</template>
6666

6767
<script setup>
68-
import { ref } from "vue";
68+
import { onMounted, ref } from "vue";
6969
import NotificationCenter from "../chat/elements/NotificationCenter.vue";
7070
import CopyIcon from "../icons/CopyIcon.vue";
7171
import DeleteIcon from "../icons/Delete2.vue";
7272
7373
const hoveredDeleteIcon = ref(null);
74-
74+
const url = ref(null);
7575
const props = defineProps({
7676
item: {
7777
type: Object,
@@ -85,6 +85,19 @@ const props = defineProps({
8585
type: String,
8686
default: "default",
8787
},
88+
getImageUrl: {
89+
type: Function,
90+
},
91+
});
92+
93+
onMounted(async () => {
94+
if (props.getImageUrl) {
95+
const imageUrl = await props.getImageUrl(
96+
props.item.collection_id,
97+
props.item.id,
98+
);
99+
url.value = imageUrl.url;
100+
}
88101
});
89102
90103
const notificationCenterRef = ref(null);

src/components/collection/VideoList.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
v-else-if="item.type === 'audio'"
3333
:item="item"
3434
:index="index"
35+
:get-audio-url="getAudioUrl"
3536
@delete-audio="$emit('delete-audio', $event)"
3637
/>
3738

3839
<ImageCard
3940
v-else-if="item.type === 'image'"
4041
:item="item"
4142
:index="index"
43+
:get-image-url="getImageUrl"
4244
@delete-image="$emit('delete-image', $event)"
4345
/>
4446
</div>
@@ -102,6 +104,12 @@ const props = defineProps({
102104
default: 4,
103105
validator: (value) => value >= 1 && value <= 4,
104106
},
107+
getImageUrl: {
108+
type: Function,
109+
},
110+
getAudioUrl: {
111+
type: Function,
112+
},
105113
});
106114
107115
const currentPage = ref(1);

src/components/hooks/useVideoDBAgent.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ export function useVideoDBAgent(config) {
9999
}
100100
};
101101

102+
const generateAudioUrl = async (collectionId, audioId) => {
103+
const res = {};
104+
try {
105+
const response = await fetch(
106+
`${httpUrl}/videodb/collection/${collectionId}/audio/${audioId}/generate_url`,
107+
);
108+
if (!response.ok) {
109+
throw new Error("Network response was not ok");
110+
}
111+
const url = await response.text();
112+
res.status = "success";
113+
res.url = url;
114+
} catch (error) {
115+
res.status = "error";
116+
res.error = error;
117+
}
118+
return res;
119+
};
120+
102121
const generateImageUrl = async (collectionId, imageId) => {
103122
const res = {};
104123
try {
@@ -618,5 +637,6 @@ export function useVideoDBAgent(config) {
618637
deleteImage,
619638
uploadMedia,
620639
generateImageUrl,
640+
generateAudioUrl,
621641
};
622642
}

0 commit comments

Comments
 (0)