Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(desktop): improve file extension handling in script #1764

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/views/script/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,26 @@ message Person {
}
}
private addExtension(name: string) {
let ext
private checkExtension(name: string): string {
let ext: string
let expectedExt: string
if (this.activeTab === this.functionTab) {
ext = '.' + this.defaultFunction[this.currentFunction].extension
expectedExt = '.' + this.defaultFunction[this.currentFunction].extension
} else {
ext = '.' + this.defaultSchema[this.currentSchema].extension
expectedExt = '.' + this.defaultSchema[this.currentSchema].extension
}
if (!name.endsWith(ext)) {
name += ext
const lastDotIndex = name.lastIndexOf('.')
if (lastDotIndex !== -1) {
ext = name.slice(lastDotIndex)
if (ext !== expectedExt) {
name = name.slice(0, lastDotIndex)
} else {
return name
}
}
return name
return name + expectedExt
}
private async save() {
Expand All @@ -426,7 +435,7 @@ message Person {
return
}
this.record.id = undefined
this.record.name = this.addExtension(this.record.name)
this.record.name = this.checkExtension(this.record.name)
this.record.script = this.activeTab === this.functionTab ? this.functionEditorValue : this.schemaEditorValue
this.record.type = this.activeTab === this.functionTab ? this.currentFunction : this.currentSchema
const data = { ...this.record }
Expand Down
Loading