-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathapp.js
63 lines (61 loc) · 1.86 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// app.js
new Vue({
el: '#app',
data: {
prompt: '',
imageFile: null,
imageUrl: null,
showIdeas: false,
ideasMarkdown: '',
renderedMarkdown: '',
isLoading: false
},
methods: {
handleImageUpload(event) {
this.imageFile = event.target.files[0];
this.imageUrl = URL.createObjectURL(event.target.files[0]);
},
getIdeas() {
this.isLoading = true;
const formData = new FormData();
formData.append('image', this.imageFile);
formData.append('prompt', this.prompt);
axios.post('/get-ideas', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
this.ideasMarkdown = response.data;
this.renderedMarkdown = marked.parse(this.ideasMarkdown);
this.showIdeas = true;
})
.catch(error => {
if (error.response && error.response.data && error.response.data.error) {
alert('Error: ' + error.response.data.error);
} else {
alert('An unexpected error occurred. Please try again later.');
}
})
.finally(() => {
this.isLoading = false;
});
}
}
});
// Initialize the marked library
marked.setOptions({
renderer: new marked.Renderer(),
highlight: function(code, language) {
const hljs = require('highlight.js');
const validLanguage = hljs.getLanguage(language) ? language : 'plaintext';
return hljs.highlight(validLanguage, code).value;
},
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
});