Skip to content

Commit

Permalink
Adjust preference for published content of project
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Oct 30, 2024
1 parent ee999cc commit 328eb49
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
7 changes: 4 additions & 3 deletions spx-gui/src/components/project/ProjectItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import { useMessageHandle } from '@/utils/exception'
import { humanizeCount, humanizeExactCount, humanizeTime, humanizeExactTime, useAsyncComputed } from '@/utils/utils'
import { getProjectEditorRoute, getProjectPageRoute } from '@/router'
import { Visibility, type ProjectData } from '@/apis/project'
import { universalUrlToWebUrl } from '@/models/common/cloud'
import { getPublishedContent, universalUrlToWebUrl } from '@/models/common/cloud'
import { useUserStore } from '@/stores/user'
import { useIsLikingProject } from '@/stores/liking'
import { UIImg, UIDropdown, UIIcon, UIMenu, UIMenuItem } from '@/components/ui'
Expand Down Expand Up @@ -141,8 +141,9 @@ const to = computed(() => {
})
const thumbnailUrl = useAsyncComputed(async () => {
if (props.project.thumbnail === '') return null
return universalUrlToWebUrl(props.project.thumbnail)
const thumbnail = getPublishedContent(props.project)?.thumbnail ?? props.project.thumbnail
if (thumbnail === '') return null
return universalUrlToWebUrl(thumbnail)
})
const { data: liking } = useIsLikingProject(() => ({
Expand Down
17 changes: 13 additions & 4 deletions spx-gui/src/models/common/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ const fileUniversalUrlSchemes = {
kodo: 'kodo:' // for objects stored in Qiniu Kodo, e.g. kodo://bucket/key
} as const

export async function load(owner: string, name: string, preferReleasedContent: boolean = false, signal?: AbortSignal) {
export async function load(owner: string, name: string, preferPublishedContent: boolean = false, signal?: AbortSignal) {
const projectData = await getProject(owner, name, signal)
if (preferReleasedContent && projectData.latestRelease != null) {
projectData.thumbnail = projectData.latestRelease.thumbnail
projectData.files = projectData.latestRelease.files
if (preferPublishedContent) {
const published = getPublishedContent(projectData)
if (published != null) {
projectData.thumbnail = published.thumbnail
projectData.files = published.files
}
}
return parseProjectData(projectData)
}

export function getPublishedContent(project: ProjectData) {
// "published content" is the latest release of a public project
if (project.visibility === Visibility.Public && project.latestRelease != null) return project.latestRelease
return null
}

export async function save(metadata: Metadata, files: Files, signal?: AbortSignal) {
const { owner, name, id } = metadata
if (owner == null) throw new Error('owner expected')
Expand Down
4 changes: 2 additions & 2 deletions spx-gui/src/models/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ export class Project extends Disposable {
}

/** Load from cloud */
async loadFromCloud(owner: string, name: string, preferReleasedContent: boolean = false, signal?: AbortSignal) {
const { metadata, files } = await cloudHelper.load(owner, name, preferReleasedContent, signal)
async loadFromCloud(owner: string, name: string, preferPublishedContent: boolean = false, signal?: AbortSignal) {
const { metadata, files } = await cloudHelper.load(owner, name, preferPublishedContent, signal)
signal?.throwIfAborted()
await this.load(metadata, files)
return this as CloudProject
Expand Down
2 changes: 1 addition & 1 deletion spx-gui/src/widgets/spx-runner/SpxRunner.ce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ watch(
errorMsg.value = ''
try {
const newProject = new Project()
await newProject.loadFromCloud(owner, name)
await newProject.loadFromCloud(owner, name, true)
project.value.dispose()
project.value = newProject
ready.value = true
Expand Down

0 comments on commit 328eb49

Please sign in to comment.