Skip to content

Commit

Permalink
feat: support ffmpeg param templates (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky authored Dec 16, 2024
1 parent 9ffacdb commit 6519447
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 16 deletions.
11 changes: 7 additions & 4 deletions src/api/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SelectOption } from 'naive-ui'
export async function getGitHubTemplates(
repo: string,
token: string = '',
extension: string = 'py',
): Promise<SelectOption[]> {
const templateList: SelectOption[] = []
const url = `https://api.github.com/repos/${repo}/contents/templates`
Expand All @@ -15,10 +16,12 @@ export async function getGitHubTemplates(
const data = await response.json()

data.forEach((item: any) => {
templateList.push({
label: item.name,
value: item.download_url,
})
if (item.name.split('.').pop() === extension) {
templateList.push({
label: item.name,
value: item.download_url,
})
}
})

return templateList
Expand Down
9 changes: 6 additions & 3 deletions src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const useSettingStore = defineStore(
const apiToken = ref('114514')

// templates
const templates: Ref<SelectOption[]> = ref([])
const vsScriptTemplates: Ref<SelectOption[]> = ref([])
const ffmpegParamTemplates: Ref<SelectOption[]> = ref([])
const templateRepo = ref('TensoRaws/vs-playground')
const githubToken = ref('')

Expand Down Expand Up @@ -50,7 +51,8 @@ export const useSettingStore = defineStore(
collapsed,
apiURL,
apiToken,
templates,
vsScriptTemplates,
ffmpegParamTemplates,
templateRepo,
githubToken,
script,
Expand All @@ -71,7 +73,8 @@ export const useSettingStore = defineStore(
'collapsed',
'apiURL',
'apiToken',
'templates',
'vsScriptTemplates',
'ffmpegParamTemplates',
'templateRepo',
'githubToken',
'script',
Expand Down
56 changes: 50 additions & 6 deletions src/views/Code.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { shallowRef } from 'vue'
import { getGitHubTemplateContent } from '@/api/github'
import { useSettingStore } from '@/store/setting'
const { darkMode, systemDarkMode, script, encodeParam, templates } = storeToRefs(useSettingStore())
const { darkMode, systemDarkMode, script, encodeParam, vsScriptTemplates, ffmpegParamTemplates } =
storeToRefs(useSettingStore())
const notification = useNotification()
Expand All @@ -33,7 +34,7 @@ function handleMount(editorInstance: any): any {
editor.value = editorInstance
}
function handleUpdateTemplate(value: string, option: SelectOption): void {
function handleUpdateVSScriptTemplate(value: string, option: SelectOption): void {
console.log('fetching template content: ' + value)
getGitHubTemplateContent(option)
.then((res) => {
Expand All @@ -42,18 +43,48 @@ function handleUpdateTemplate(value: string, option: SelectOption): void {
.catch((err) => {
console.error(err)
notification['error']({
title: 'Failed to get template content',
title: 'Failed to get vs script template content',
content: String(err),
})
})
}
function handleUpdateFFmpegParamTemplate(value: string, option: SelectOption): void {
console.log('fetching template content: ' + value)
getGitHubTemplateContent(option)
.then((res) => {
encodeParam.value = res
})
.catch((err) => {
console.error(err)
notification['error']({
title: 'Failed to get ffmpeg encode param template content',
content: String(err),
})
})
}
function handleEncodeParamChange(value: string): void {
console.log('encode param changed: ' + value)
// 如果输入的字符串里面包含了换行符,提醒用户
if (value.includes('\n') || value.includes('\r') || value.includes('\r\n')) {
notification['error']({
title: 'Encode param contains line breaks!!!!!',
content: 'Please remove line breaks',
})
}
}
</script>

<template>
<NSpace vertical>
<NSpace justify="space-between">
<NGradientText size="18" type="primary"> Code </NGradientText>
<NSelect :options="templates" style="width: 50vh" @update:value="handleUpdateTemplate" />
<NSelect
:options="vsScriptTemplates"
style="width: 50vh"
@update:value="handleUpdateVSScriptTemplate"
/>
</NSpace>
<NCard hoverable size="small" style="width: 100%; height: 65vh">
<VueMonacoEditor
Expand All @@ -65,8 +96,21 @@ function handleUpdateTemplate(value: string, option: SelectOption): void {
@mount="handleMount"
/>
</NCard>
<NCard hoverable title="Encode Param" size="small" style="width: 100%">
<NInput v-model:value="encodeParam" type="textarea" placeholder="Encode Param" />
<NSpace justify="space-between">
<NGradientText size="18" type="primary"> Encode Param </NGradientText>
<NSelect
:options="ffmpegParamTemplates"
style="width: 50vh"
@update:value="handleUpdateFFmpegParamTemplate"
/>
</NSpace>
<NCard hoverable size="small" style="width: 100%">
<NInput
v-model:value="encodeParam"
type="textarea"
placeholder="Encode Param"
@change="handleEncodeParamChange"
/>
</NCard>
</NSpace>
</template>
Expand Down
17 changes: 14 additions & 3 deletions src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import router from '@/router'
import { useSettingStore } from '@/store/setting'
import List from '@/views/List.vue'
const { templateRepo, templates, githubToken } = storeToRefs(useSettingStore())
const { templateRepo, vsScriptTemplates, ffmpegParamTemplates, githubToken } =
storeToRefs(useSettingStore())
const notification = useNotification()
Expand All @@ -33,9 +34,19 @@ onMounted(() => {
})
})
getGitHubTemplates(templateRepo.value, githubToken.value)
getGitHubTemplates(templateRepo.value, githubToken.value, 'py')
.then((res) => {
templates.value = res
console.log(res)
vsScriptTemplates.value = res
})
.catch((error) => {
console.log(error)
})
getGitHubTemplates(templateRepo.value, githubToken.value, 'txt')
.then((res) => {
console.log(res)
ffmpegParamTemplates.value = res
})
.catch((error) => {
console.log(error)
Expand Down

0 comments on commit 6519447

Please sign in to comment.