gpt4 book ai didi

javascript - 为什么我的对象的值是一个函数而不是一个字符串?

转载 作者:行者123 更新时间:2023-12-04 09:44:12 25 4
gpt4 key购买 nike

我有一个事件的更新功能。用户可能是否添加了预告视频。如果他们有我想上传它并使用下载 url 保存该对象。

我使用不同的函数来上传视频,并且只有在用户附加视频时才调用它。

但是当我尝试更新时,它告诉我我正在尝试写入一个无效的对象,因为 teaser 中的数据是一个函数,我希望它是一个字符串(下载 url,或者只是一个空字符串。

我究竟做错了什么?

这就是我调用函数的方式:

updateEvent(values, videoAsFile, () => {
setIsEventEdited(false);
setCurrentEvent(values);
})

然后是这些功能:
const uploadTeaserVideo = (event, video) => async () => {
const ref = storage.ref(`/videos/events/${event.id}/`);

const upload = await ref.put(video);
if (!upload) return "";

const downloadUrl = await ref.getDownloadURL();
if (!downloadUrl) return "";

return downloadUrl;
};

export const updateEvent = (values, teaserVideo, cb) => async () => {

if (teaserVideo) {
const teaser = await uploadTeaserVideo(values, teaserVideo);
db.collection("events")
.doc(values.id)
.set({ ...values, teaser })
.then(() => {
cb();
});
} else {
db.collection("events")
.doc(values.id)
.set(values)
.then(() => {
cb();
});
}
};

我查过了, teaserVideo是有效的视频文件,如果未选择视频,则为 null。

最佳答案

uploadTeaserVideo被定义为一个返回函数的函数:

//                                       vv−−−−−−−−−−−−−−− Start of the uploadTeaserVideo function body
const uploadTeaserVideo = (event, video) => async () => {
// ^^−−− Start of the body of the function it returns
const ref = storage.ref(`/videos/events/${event.id}/`);

const upload = await ref.put(video);
if (!upload) return "";

const downloadUrl = await ref.getDownloadURL();
if (!downloadUrl) return "";

return downloadUrl;
};

我怀疑你的意思是它是 async返回( promise )的函数 downloadUrl :
const uploadTeaserVideo = async (event, video) => {

关于javascript - 为什么我的对象的值是一个函数而不是一个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62195498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com