-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hosting): Create project in dev.
- Loading branch information
1 parent
2d48adc
commit 0b852e5
Showing
4 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { App, Modal, Setting, requestUrl } from "obsidian"; | ||
import type InvioPlugin from "../main"; // unavoidable | ||
import type { TransItemType } from "../i18n"; | ||
import svg from '../utils/svg'; | ||
import { log } from '../moreOnLog'; | ||
|
||
export class CreateProjectModal extends Modal { | ||
readonly plugin: InvioPlugin; | ||
readonly name: string; | ||
slug: string; | ||
domain: string; | ||
confirmCB: any; | ||
constructor(app: App, plugin: InvioPlugin, name: string, slug: string, domain: string, cb?: any) { | ||
super(app); | ||
this.plugin = plugin; | ||
this.name = name; | ||
this.slug = slug; | ||
this.domain = domain; | ||
this.confirmCB = cb; | ||
} | ||
async createProject() { | ||
const token = this.plugin.settings.token; | ||
if (!token) { | ||
throw new Error('NoAuth'); | ||
} | ||
// require('request')(`http://localhost:8888/api/invio?priatoken=${token}`, {}, (error, response, body) => { | ||
// console.log(JSON.parse(body)); | ||
// }); | ||
return fetch(`http://localhost:8888/api/invio?priatoken=${token}`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
name: this.name, | ||
slug: this.slug, | ||
domain: this.domain || '' | ||
}) | ||
}) | ||
.then(resp => resp.json()) | ||
.then(resp => { | ||
log.info('create project resp - ', resp); | ||
return resp | ||
}) | ||
.catch(err => { | ||
log.error('create project failed: ', JSON.stringify(err)); | ||
}) | ||
} | ||
|
||
onOpen() { | ||
let { contentEl } = this; | ||
const t = (x: TransItemType, vars?: any) => { | ||
return this.plugin.i18n.t(x, vars); | ||
}; | ||
|
||
contentEl.createEl("h2", { | ||
text: 'Create a new Project' | ||
}); | ||
|
||
const formContainer = contentEl.createDiv('form-container'); | ||
// formContainer.innerHTML = 'FORM' | ||
|
||
new Setting(formContainer) | ||
.setName('Name') | ||
.setDesc('Current directory name') | ||
.addText((text) => | ||
text | ||
.setPlaceholder("") | ||
.setValue(this.name) | ||
.setDisabled(true) | ||
); | ||
new Setting(formContainer) | ||
.setName('Slug') | ||
.setDesc('Slug of Sub domain') | ||
.addText((text) => | ||
text | ||
.setPlaceholder("") | ||
.setValue(this.slug) | ||
.onChange(txt => { | ||
this.slug = txt; | ||
log.info('slug changed: ', this.slug); | ||
}) | ||
); | ||
new Setting(formContainer) | ||
.setName('Domain') | ||
.setDesc('Your custom domain') | ||
.addText((text) => | ||
text | ||
.setPlaceholder("www.baidu.com") | ||
.setValue(this.domain) | ||
.onChange(txt => { | ||
this.domain = txt; | ||
log.info('domain changed: ', this.domain); | ||
}) | ||
); | ||
|
||
new Setting(formContainer) | ||
.addButton((button) => { | ||
button.setButtonText('cancel'); | ||
button.onClick(async () => { | ||
// this.plugin.settings.password = this.newPassword; | ||
// await this.plugin.saveSettings(); | ||
// new Notice(t("modal_password_notice")); | ||
this.close(); | ||
}); | ||
}) | ||
.addButton((button) => { | ||
button.setClass("password-second-confirm"); | ||
button.setButtonText('Confirm'); | ||
button.onClick(async () => { | ||
await this.createProject(); | ||
this.confirmCB && this.confirmCB(); | ||
this.close(); | ||
}); | ||
}); | ||
} | ||
|
||
onClose() { | ||
let { contentEl } = this; | ||
contentEl.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Vault, requestUrl, RequestUrlParam } from "obsidian"; | ||
import InvioPlugin from "./main"; | ||
|
||
// const param: RequestUrlParam = { | ||
// body: transformedBody, | ||
// headers: transformedHeaders, | ||
// method: method, | ||
// url: url, | ||
// contentType: contentType, | ||
// }; | ||
|
||
// Check hosting service | ||
export const checkRemoteHosting = async (plugin: InvioPlugin) => { | ||
const curDir = plugin.settings.localWatchDir; | ||
if (!curDir) { | ||
return false; | ||
} | ||
const token = plugin.settings.token; | ||
if (!token) { | ||
throw new Error('NoAuth'); | ||
} | ||
return fetch(`http://localhost:8888/api/invio?priatoken=${token}`) | ||
.then(resp => resp.json()) | ||
.then(resp => { | ||
console.log('projects: ', resp); | ||
if (resp?.find((p: any) => p.name === curDir)) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters