Skip to content

Commit

Permalink
feat: use new API for Programming Language Detection
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangbh-0986 committed Feb 19, 2021
1 parent b895426 commit bb53926
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

export const detectCode = data => axios.post('/_/programming_language_detect', data)
export const detectCode = data => axios.post('/_/viblo-programming-language-detection/', data)
export const detectSpam = data => axios.post('/_/spam_detect', data)
export const tagCompare = data => axios.post('/_/tag_compare', data)
export const autoTagging = data => axios.post('/_/auto_tagging', data)
Expand Down
23 changes: 6 additions & 17 deletions app/contents/form-default/programming-language-detection.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
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 =
"```\n5.times.each do |n|\nputs n\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 = [
null
]
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

0 comments on commit bb53926

Please sign in to comment.