Skip to content

Commit

Permalink
Merge pull request #465 from LucienShui/feature/fit_backend_version_3…
Browse files Browse the repository at this point in the history
….5.0

Feature/fit backend version 3.5.0
  • Loading branch information
LucienShui authored Sep 30, 2021
2 parents cc47de0 + 2f41a30 commit 76e8e1d
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 72 deletions.
25 changes: 13 additions & 12 deletions e2e_test/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_key(self) -> str:
@classmethod
def beat(cls) -> dict:
return {
'status': 200
'code': 200
}

def create(self, body: dict) -> dict:
Expand All @@ -29,11 +29,11 @@ def create(self, body: dict) -> dict:
with self.db_lock:
self.database[key] = body
return {
'status': 201,
'code': 201,
'key': key
}

def get(self, key: str, password: str) -> dict:
def get(self, key: str, password: str) -> (dict, int):
with self.db_lock:
if key in self.database:
paste: dict = self.database[key]
Expand All @@ -42,29 +42,29 @@ def get(self, key: str, password: str) -> dict:
if paste['create_time'] + timedelta(minutes=paste['expire_minute']) < datetime.now():
self.database.pop(key)
return {
'status': 404,
'code': 40402,
'message': 'paste not found'
}
}, 404

if password == paste.get('password', ''):
if paste['self_destruct']:
paste['expire_count'] -= 1
if paste['expire_count'] == 0:
self.database.pop(key)
return {
'status': 200,
'code': 200,
'lang': paste['lang'],
'content': paste['content']
}
}, 200
else:
return {
'status': 403,
'code': 40301,
'message': 'wrong password'
}
}, 403
return {
'status': 404,
'code': 40402,
'message': 'paste not found'
}
}, 404


app = Flask(__name__)
Expand All @@ -83,7 +83,8 @@ def create():

@app.route('/api/v3/paste/<key>', methods=['GET'])
def get(key: str):
return jsonify(backend.get(key, request.args.get('password', '')))
response, code = backend.get(key, request.args.get('password', ''))
return jsonify(response), code


def main():
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pasteme",
"version": "3.3.1",
"version": "3.4.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
26 changes: 13 additions & 13 deletions src/assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ function getLast(value) {
return value[value.length - 1];
}

function errorHandler(error, alert_error = true) {
if (alert_error) {
alert(JSON.stringify({
message: error.message,
method: error.config.method,
url: error.config.url,
params: error.config.params
}))
}
}

export default {
get: function (url, params = {}, alert_error = true) {
Expand All @@ -26,7 +16,7 @@ export default {
}).then(response => {
resolve(response.data);
}).catch(error => {
errorHandler(error, alert_error);
this.errorHandler(error, alert_error);
reject(error);
});
});
Expand All @@ -36,7 +26,7 @@ export default {
axios.post(url, params).then(response => {
resolve(response.data);
}).catch(error => {
errorHandler(error);
this.errorHandler(error);
reject(error);
});
});
Expand All @@ -46,7 +36,7 @@ export default {
axios.put(url, params).then(response => {
resolve(response.data);
}).catch(error => {
errorHandler(error);
this.errorHandler(error);
reject(error);
});
});
Expand All @@ -55,4 +45,14 @@ export default {
let result = args.map(pathPart => pathPart.replace(/(^\/|\/$)/g, "")).join("/");
return result + (getLast(getLast(args)) === '/' ? '/' : '');
},
errorHandler: function (error, alert_error = true) {
if (alert_error) {
alert(JSON.stringify({
message: error.message,
method: error.config.method,
url: error.config.url,
params: error.config.params
}))
}
}
}
6 changes: 3 additions & 3 deletions src/assets/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const lang = {
h2: '保存成功',
p: [
{
text: '欲访问 <strong>{key}</strong> 所对应的 Paste'
text: '欲访问 <strong>{key}</strong> 所对应的一贴'
},
{
button: '返回主页'
Expand All @@ -49,7 +49,7 @@ export const lang = {
],
},
popover: {
text: '在这里填入 <strong>索引</strong> 即可查看相应的 Paste'
text: '在这里填入 <strong>索引</strong> 即可查看相应的一贴'
},
badge: {
copy: '复制链接',
Expand All @@ -59,7 +59,7 @@ export const lang = {
},
auth: {
form: {
label: '此 Paste 已加密,请输入密码:',
label: '此一贴已加密,请输入密码:',
button: '提交',
placeholder: '密码错误'
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export default {
this.api.post(
this.api.join(this.$store.getters.config.api.backend, 'paste/'),
this.form
).then(({status, key, message}) => {
if (status === 201) {
).then(({code, key, message}) => {
if (code === 201) {
this.updateView("success");
this.updateKey(key);
} else {
alert(status + ': ' + message)
alert(code + ': ' + message)
}
})
}
Expand Down
63 changes: 36 additions & 27 deletions src/components/PasswordAuth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<b-form @submit.prevent="onSubmit">
<b-form-group :label="$t('lang.auth.form.label')">
<b-form-input
type="password"
v-model="form.password"
v-focus
:placeholder="flag ? '' : this.$t('lang.auth.form.placeholder')">
</b-form-input>
type="password"
v-model="form.password"
v-focus
:placeholder="flag ? '' : this.$t('lang.auth.form.placeholder')">
</b-form-input>
</b-form-group>
<b-button type="submit" variant="primary">{{ $t('lang.auth.form.button') }}</b-button>
</b-form>
Expand All @@ -18,34 +18,43 @@
</template>

<script>
import stateMixin from "../assets/js/mixins/stateMixin";
export default {
name: "PasswordAuth",
mixins: [stateMixin],
data() {
return {
flag: true,
form: {
password: null,
}
import stateMixin from "../assets/js/mixins/stateMixin";
export default {
name: "PasswordAuth",
mixins: [stateMixin],
data() {
return {
flag: true,
form: {
password: null,
}
},
methods: {
onSubmit() {
const sendUrl = this.api.join(this.$store.getters.config.api.backend, 'paste', this.$route.params.key);
this.api.get(sendUrl, this.form).then(({status, content, lang}) => {
if (status === 200) {
this.updateContent(content);
this.updateLang(lang === "plain" ? "plaintext" : lang);
this.updateView("paste_view");
} else {
}
},
methods: {
onSubmit() {
const sendUrl = this.api.join(this.$store.getters.config.api.backend, 'paste', this.$route.params.key);
this.api.get(sendUrl, this.form, false).then(({content, lang}) => {
this.updateContent(content);
this.updateLang(lang === "plain" ? "plaintext" : lang);
this.updateView("paste_view");
}).catch(error => {
if (error.response) {
let data = error.response.data;
if (data.code === 40301) {
this.flag = false;
this.form.password = null;
return
} else if (data.code === 40402) {
this.$router.push("What_are_you_nong_sha_lei?");
return
}
});
}
}
this.api.errorHandler(error);
});
}
}
}
</script>

<style scoped>
Expand Down
24 changes: 15 additions & 9 deletions src/views/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,22 @@ export default {
this.updateView("loading");
let url = this.api.join(this.config.api.backend, 'paste', this.$route.params.key)
this.api.get(url).then(({status, content, lang}) => {
if (status === 200) {
this.updateView("paste_view");
this.updateContent(content);
this.updateLang(lang === "plain" ? "plaintext" : lang);
} else if (status === 403) {
this.updateView("password_auth");
} else {
this.$router.push("What_are_you_nong_sha_lei?");
this.api.get(url, {}, false).then(({content, lang}) => {
this.updateView("paste_view");
this.updateContent(content);
this.updateLang(lang === "plain" ? "plaintext" : lang);
}).catch(error => {
if (error.response) {
let data = error.response.data;
if (data.code === 40301) {
this.updateView("password_auth");
return
} else if (data.code === 40402) {
this.$router.push("What_are_you_nong_sha_lei?");
return
}
}
this.api.errorHandler(error);
});
},
},
Expand Down
4 changes: 2 additions & 2 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ module.exports = {
proxy: {
"/api/v3/": {
secure: false,
// target: "http://dev.pasteme.lucien.ink/",
target: "http://localhost:8000/",
target: "http://dev.pasteme.lucien.ink/",
// target: "http://localhost:8000/",
changeOrigin: true
}
}
Expand Down

0 comments on commit 76e8e1d

Please sign in to comment.