Skip to content

Commit

Permalink
build: fix all ts error
Browse files Browse the repository at this point in the history
  • Loading branch information
nexmoe committed May 1, 2024
1 parent 9362ca5 commit 75db03b
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 152 deletions.
4 changes: 2 additions & 2 deletions components/module/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const text = extractTextFromHTML(props.module.content)
/>

<h3
v-if="!flow.configNoTitle"
v-if="flow?.configNoTitle"
class="text-base font-bold tracking-tight text-black truncate"
>
{{ props.module.title }}
</h3>
</div>

<div
v-if="!flow.configNoContent"
v-if="flow?.configNoContent"
class="truncate"
>
<div v-html="text" />
Expand Down
14 changes: 14 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@ declare module '*.svg' {
const component: DefineComponent
export default component
}

declare module 'probe-image-size' {
interface Props {
width: number
height: number
type: string
mime: string
wUnits: string
hUnits: string
url: string
}

export default function probe(url: string): Promise<Props>
}
2 changes: 0 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export default defineNuxtConfig({
},
},

extends: ['@sidebase/core'],

image: {
format: ['webp'],
quality: 85,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@nuxt/image": "^1.5.0",
"@pinia/nuxt": "^0.5.1",
"@prisma/client": "^5.12.1",
"@sidebase/core": "^0.1.4",
"@trpc/client": "^10.45.2",
"@trpc/server": "^10.45.2",
"@vitest/coverage-v8": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion pages/module/[id].vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
const id = useRoute().params.id
const id = useRoute().params.id as string
const useImg = useImage()
const { $client } = useNuxtApp()
Expand Down
2 changes: 1 addition & 1 deletion pages/space/_[id].vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script setup lang="ts">
<script setup>
const id = useRoute().params.id
const { data: space, error } = useFetch(`/api/space/${id}`)
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 19 additions & 29 deletions server/flowing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { consola } from 'consola'
import { type API, type Flow, PrismaClient } from '@prisma/client'
import { type Prisma, type API, PrismaClient } from '@prisma/client'
import probe from 'probe-image-size'
import type { NModule } from '~/composables/adapter/types'
import useAdapter from '~/composables/adapter/useAdapter'
Expand Down Expand Up @@ -120,45 +120,34 @@ async function upsert(ele: NModule, flowId: string) {
// 如果找到已存在的模块,则打印信息并更新
if (res) {
consola.info(`Exists: ${ele.title}`)
let data = {
title: ele.title,
content: ele.content,
image: ele.image,
date: ele.date,
}
if (result?.width && result?.height) {
data = {
...data,
imageWidth: result.width,
imageHeight: result.height,
}
}

await prisma.module.update({
where: {
id: res.id,
},
data,
data: {
title: ele.title,
content: ele.content,
image: ele.image,
date: ele.date,
imageWidth: result?.width || null,
imageHeight: result?.height || null,
},
})
return
}

// 如果未找到已存在的模块,则打印成功消息并尝试插入新模块
consola.success(`Add: ${ele.title}`)
try {
let data = {
...ele,
date: ele.date || new Date().toISOString(),
flowId,
}
if (result?.width && result?.height) {
data = {
...data,
imageWidth: result.width,
imageHeight: result.height,
}
}
await prisma.module.create({
data,
data: {
...ele,
date: ele.date || new Date().toISOString(),
flowId,
imageWidth: result?.width || null,
imageHeight: result?.height || null,
},
})
}
catch (error) {
Expand All @@ -178,7 +167,7 @@ async function upsert(ele: NModule, flowId: string) {
*
* 对于所有成功抓取的数据适配器,将它们保存到数据库中的module表。
*/
async function flowingByFlow(flow: Flow) {
async function flowingByFlow(flow: Prisma.FlowGetPayload<{ include: { api: true } }>) {
const tasks = flow.api.map((api: API) => {
return (async () => {
let originIndex = 0
Expand Down Expand Up @@ -246,6 +235,7 @@ export async function allSize() {
},
})
for (const module of modules) {
if (!module.image) continue
const result = await probe(module.image)
if (result?.width && result?.height) {
consola.success(`Image size updated: ${module.title} `)
Expand Down
9 changes: 2 additions & 7 deletions tests/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ await setup({
})

describe('app', () => {
it('renders welcome page', async () => {
it('renders home page', async () => {
const html = await $fetch('/')

// Shows expected text
expect(html).toContain('is the productive Nuxt 3 stack')

// Contains data from healthcheck endpoint
expect(html).toContain('Server v0.0.1 initialized')
expect(html).toContain('Started at ')
expect(html).toContain('Last checked at ')
expect(html).toContain('Copyright')

await expectNoClientErrors('/')
})
Expand Down
Loading

0 comments on commit 75db03b

Please sign in to comment.