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

feat: use new API for Programming Language Detection #8

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion app/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'

export const detectCode = data => axios.post('/_/programming_language_detect', data)
export const detectSpam = data => axios.post('/_/viblo-lang-and-spam-detection/', data)
export const detectCode = data => axios.post('/_/viblo-programming-language-detection/', data)
export const tagCompare = data => axios.post('/_/tag_compare', data)
export const autoTagging = data => axios.post('/_/auto_tagging', data)
export const detectLanguage = data => axios.post('/_/language_detect', data)
Expand Down
21 changes: 4 additions & 17 deletions app/contents/form-default/programming-language-detection.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
export const code =
`
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.example.com/');
export const post_id = 0

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
export const content =
"``` \r\nexport default {\r\n computed: {\r\n myGetter() {\r\n return this.$store.getters['myModule\/myGetter'];\r\n },\r\n myGetter2() {\r\n return this.$store.getters['myModule\/myGetter2'];\r\n }\r\n },\r\n\r\n methods: {\r\n myAction() {\r\n this.$store.dispatch('myModule\/myAction');\r\n },\r\n myAction2() {\r\n this.$store.dispatch('myModule\/myAction2');\r\n }\r\n }\r\n};\r\n```"

// Another example, let's get a web page into a string. See also file_get_contents().
$html = implode('', file('http://www.example.com/'));

// Using the optional flags parameter since PHP 5
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
`
export const tag = []
15 changes: 10 additions & 5 deletions app/pages/_lang/programming-language-detection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<el-form slot="form" :model="form">
<el-form-item :label="$t('form.labels.enter_your_code')">
<el-input
v-model="form.code"
v-model="form.content"
:autosize="{ minRows: 6 }"
type="textarea"
@input="result = null"/>
</el-form-item>

<el-form-item class="flex flex--center">
<el-button
:disabled="!form.code"
:disabled="!form.content"
:loading="processing"
type="primary"
@click="onSubmit">
Expand All @@ -23,7 +23,12 @@
<div slot="result" style="max-width: 40rem">
<el-alert :closable="false" type="success" title show-icon>
<span class="mr-1">{{ $t('form.labels.detected_programming_language') }}:</span>
<strong>{{ result }}</strong>
<strong
v-for="(item, index) in result"
:key="index"
>
{{item.language}}
</strong>
</el-alert>

<btn-try-again @click="result = null"/>
Expand All @@ -35,7 +40,7 @@
import { detectCode } from '~/api'
import { servicePage } from '~/utils/page'
import { getServiceItem } from '~/contents/services'
import * as formDefault from '~/contents/form-default/programming-language-detection'
import * as formDefault from '~/contents/form-default/programming-language-detection'

export default {
data() {
Expand All @@ -51,7 +56,7 @@
onSubmit() {
this.processing = true
return detectCode(this.form)
.then(({ data }) => this.result = data.data.programming_language)
.then(({ data }) => this.result = data.code)
.catch(_ => this.$message.error(this.$t('errors.something_wrong')))
.finally(() => this.processing = false)
}
Expand Down