26 lines
727 B
TypeScript
26 lines
727 B
TypeScript
import { useEffect, useState } from 'react';
|
|
import { useNovaKit } from '@/components/nova-sdk/context/useNovaKit';
|
|
import type { TaskArtifact } from '@/components/nova-sdk/types';
|
|
|
|
export const useLoadContent = (
|
|
taskArtifact: TaskArtifact
|
|
) => {
|
|
const [content, setContent] = useState('');
|
|
const { api } = useNovaKit();
|
|
useEffect(() => {
|
|
if (taskArtifact.path) {
|
|
api
|
|
.getArtifactUrl?.(taskArtifact)
|
|
.then(async (res) => {
|
|
const url = res?.data || '';
|
|
if (url) {
|
|
const content = await fetch(url).then((res) => res.text());
|
|
setContent(content);
|
|
}
|
|
})
|
|
.catch(() => { });
|
|
}
|
|
}, [taskArtifact, api]);
|
|
return content;
|
|
};
|