♻️ Fully typed API

This commit is contained in:
2025-09-19 01:21:38 +08:00
parent 7904ce9ca7
commit 60e8b1dcfb
13 changed files with 276 additions and 26 deletions

View File

@@ -6,8 +6,9 @@
<script lang="ts" setup>
import { computed } from 'vue'
import type { SnAttachment } from '~/types/api'
const props = defineProps<{ item: any }>()
const props = defineProps<{ item: SnAttachment }>()
const itemType = computed(() => props.item.mime_type.split('/')[0] ?? 'unknown')

View File

@@ -47,13 +47,20 @@ import { useSolarNetwork } from '~/composables/useSolarNetwork'
import PubSelect from './PubSelect.vue'
// Interface for uploaded files in the editor
interface UploadedFile {
name: string
url: string
type: string
}
const emits = defineEmits(['posted'])
const publisher = ref<string | undefined>()
const content = ref('')
const selectedFiles = ref<File[]>([])
const fileList = ref<any[]>([])
const fileList = ref<UploadedFile[]>([])
const submitting = ref(false)
@@ -103,7 +110,7 @@ function uploadFile(file: File) {
onError: function (error) {
console.error('[DRIVE] Upload failed:', error)
},
onProgress: function (bytesUploaded, bytesTotal) {
onProgress: function (_bytesUploaded, _bytesTotal) {
// Could show progress
},
onSuccess: function (payload) {
@@ -122,7 +129,7 @@ function uploadFile(file: File) {
},
})
upload.findPreviousUploads().then(function (previousUploads) {
if (previousUploads.length) {
if (previousUploads.length > 0 && previousUploads[0]) {
upload.resumeFromPreviousUpload(previousUploads[0])
}
upload.start()

View File

@@ -5,14 +5,19 @@
<post-header :item="props.item" />
<div v-if="props.item.title || props.item.description">
<h2 v-if="props.item.title" class="text-lg">{{ props.item.title }}</h2>
<h2 v-if="props.item.title" class="text-lg">
{{ props.item.title }}
</h2>
<p v-if="props.item.description" class="text-sm">
{{ props.item.description }}
</p>
</div>
<article v-if="htmlContent" class="prose prose-sm dark:prose-invert prose-slate prose-p:m-0">
<div v-html="htmlContent"/>
<article
v-if="htmlContent"
class="prose prose-sm dark:prose-invert prose-slate prose-p:m-0"
>
<div v-html="htmlContent" />
</article>
<div v-if="props.item.attachments" class="d-flex gap-2 flex-wrap">
@@ -28,23 +33,25 @@
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue'
import { Marked } from 'marked'
import { ref, watch } from "vue"
import { Marked } from "marked"
import type { SnPost } from "~/types/api"
import PostHeader from './PostHeader.vue'
import AttachmentItem from './AttachmentItem.vue'
import PostHeader from "./PostHeader.vue"
import AttachmentItem from "./AttachmentItem.vue"
const props = defineProps<{ item: any }>()
const props = defineProps<{ item: SnPost }>()
const marked = new Marked()
const htmlContent = ref<string>('')
const htmlContent = ref<string>("")
watch(
props.item,
async (value) => {
if (value.content) htmlContent.value = await marked.parse(value.content)
if (value.content)
htmlContent.value = await marked.parse(value.content, { breaks: true })
},
{ immediate: true, deep: true },
{ immediate: true, deep: true }
)
</script>