X Tutup
Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .envs_example/.local/.front-ms
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_APP_VUEX_STRICT=true

VITE_APP_WSGI_BASE_URL=http://localhost:8000
VITE_APP_ASGI_BASE_URL=ws://localhost:8000
VITE_APP_AUTH_BASE_URL=http://localhost:5000
VITE_APP_RACE_BASE_URL=http://localhost:8000
4 changes: 2 additions & 2 deletions .envs_example/.production/.front-ms
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_APP_VUEX_STRICT=true

VITE_APP_WSGI_BASE_URL=http://localhost:8000
VITE_APP_ASGI_BASE_URL=ws://localhost:8000
VITE_APP_AUTH_BASE_URL=http://localhost:5000
VITE_APP_RACE_BASE_URL=http://localhost:8000
14 changes: 6 additions & 8 deletions front-ms/src/api/api.js → front-ms/src/api/auth/api.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import axios from "axios";
import humps from "humps";
// import qs from "qs";
import CONF from "../config";
import router from "../router";
import store from "../store";
import CONF from "@/config";
import router from "@/router";
import store from "@/store";
import { Notify } from "quasar";
import { Auth } from ".";
import User from "./user";

const api = axios.create({
baseURL: `${CONF.WSGI_BASE_URL}/`,
baseURL: `${CONF.AUTH_BASE_URL}/`,
headers: {
Authorization: localStorage.getItem("access_token") ? `Token ${localStorage.getItem("access_token")}` : "",
},
Expand Down Expand Up @@ -62,10 +62,8 @@ api.interceptors.response.use(
// }

if (error.response.status === 401) {
console.log(localStorage.getItem("refresh_token"))
if (localStorage.getItem("refresh_token")) {
console.log('--------------')
Auth.refreshToken()
User.refreshToken()
.then((r) => {
localStorage.setItem("access_token", r.data.accessToken);
localStorage.setItem("refresh_token", r.data.refreshToken);
Expand Down
7 changes: 7 additions & 0 deletions front-ms/src/api/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import api from "./api";
import User from "./user";

export {
api,
User,
}
2 changes: 0 additions & 2 deletions front-ms/src/api/auth.js → front-ms/src/api/auth/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import api from "./api";

const EDN_POINT = "";

export default {
getCredentials() {
const ACCESS_TOKEN = localStorage.getItem("access_token");
Expand Down
93 changes: 0 additions & 93 deletions front-ms/src/api/index.js

This file was deleted.

84 changes: 84 additions & 0 deletions front-ms/src/api/race/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import axios from "axios";
import humps from "humps";
// import qs from "qs";
import CONF from "@/config";
import router from "@/router";
import store from "@/store";
import { Notify } from "quasar";

const api = axios.create({
baseURL: `${CONF.RACE_BASE_URL}/`,
transformResponse: [
function (data) {
// Конвертируем все имена переменных в camelKeys
if (data && typeof data === "string") {
return humps.camelizeKeys(JSON.parse(data));
}

return data;
},
],
// transformRequest: [
// function (data, headers) {
// if (data && typeof data === "object") {
// // Конвертируем все имена переменных в snake_case
// if (data instanceof FormData) {
// const formData = new FormData();

// for (const [key, value] of data.entries()) {
// formData.append(humps.decamelize(key, { split: /(?=[A-Z0-9])/ }), value);
// }

// return formData;
// }

// return humps.decamelizeKeys(data, { split: /(?=[A-Z0-9])/ });
// }

// return data;
// },
// ...axios.defaults.transformRequest,
// ],
// paramsSerializer: {
// serialize: (params) => {
// const decamelizedParams = humps.decamelizeKeys(params, { split: /(?=[A-Z0-9])/ });
// return qs.stringify(decamelizedParams, { indices: false });
// },
// },
});

// api.interceptors.response.use(
// (response) => {
// return response;
// },
// (error) => {
// if (error.response) {
// // for (const property in error.response.data) {
// // Notify.create({ type: "warning", timeout: 5000, message: error.response.data[property] });
// // }

// if (error.response.status === 401) {
// if (localStorage.getItem("refresh_token")) {
// Auth.refreshToken()
// .then((r) => {
// localStorage.setItem("access_token", r.data.accessToken);
// localStorage.setItem("refresh_token", r.data.refreshToken);
// router.push("/");
// })
// .catch((e) => {});
// store.commit("RESET_STATE");
// router.push("/log-in");
// }
// }
// }

// // Если сервер недоступен
// if (error.request.status === 0) {
// Notify.create({ timeout: 3000, message: "Не удалось установить соединение с сервером" });
// }

// return Promise.reject(error);
// }
// );

export default api;
5 changes: 5 additions & 0 deletions front-ms/src/api/race/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RegexRace from "./regex-race";

export {
RegexRace,
}
23 changes: 23 additions & 0 deletions front-ms/src/api/race/regex-race.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import api from "./api";

const EDN_POINT = "/regex-race";

export default {
Learn: {
list(params = {}) {
return api.get(`${EDN_POINT}/learn`, { params: params });
},
validateAnswer(data) {
return api.post(`${EDN_POINT}/learn/`, data);
},
// create(data) {
// return api.post(`${EDN_POINT}/educations/`, data);
// },
// update(id, data) {
// return api.patch(`${EDN_POINT}/educations/${id}/`, data);
// },
// delete(id) {
// return api.delete(`${EDN_POINT}/educations/${id}/`);
// },
},
};
4 changes: 2 additions & 2 deletions front-ms/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { version } from '../../package.json';
const CONF = Object.freeze({
VERSION: version,
VUEX_STRICT: import.meta.env.VITE_APP_VUEX_STRICT === "true",
WSGI_BASE_URL: import.meta.env.VITE_APP_WSGI_BASE_URL,
ASGI_BASE_URL: import.meta.env.VITE_APP_ASGI_BASE_URL,
AUTH_BASE_URL: import.meta.env.VITE_APP_AUTH_BASE_URL,
RACE_BASE_URL: import.meta.env.VITE_APP_RACE_BASE_URL,
});

export default CONF;
9 changes: 8 additions & 1 deletion front-ms/src/pages/games/regex-race/game.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,18 @@
</template>

<script setup>
import { ref } from "vue";
import { ref, onMounted } from "vue";
import gameCanvas from "./game-canvas.vue";
import { RegexRace } from "@/api/race";

const numPlayers = ref(4);
const numTasks = ref(5);

const increaseNumberOfPlayers = () => (numPlayers.value += 1);

onMounted(async () => {
await RegexRace.Learn.list()
.then((r) => console.log(r.data))
.catch((e) => {});
})
</script>
Empty file.
4 changes: 2 additions & 2 deletions front-ms/src/pages/log-in/log-in.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<script setup>
import { ref, computed } from "vue";
import { required } from "@/utils/validators";
import { Auth } from "@/api";
import { User } from "@/api/auth";
import { useRouter } from "vue-router";

const router = useRouter();
Expand Down Expand Up @@ -87,7 +87,7 @@ const onLogIn = async () => {
formData.append("username", form.value.username);
formData.append("password", form.value.password);

await Auth.login(formData)
await User.login(formData)
.then((r) => {
localStorage.setItem("access_token", r.data.accessToken);
localStorage.setItem("refresh_token", r.data.refreshToken);
Expand Down
4 changes: 2 additions & 2 deletions front-ms/src/store/modules/app/actions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Auth } from "../../../api";
import { User } from "@/api/auth";
import router from "@/router";

export const getUser = async (ctx) => {

await Auth.getCredentials()
await User.getCredentials()
.then((r) => ctx.commit("SET_USER", r.data))
.catch((e) => {});
};
Expand Down
2 changes: 1 addition & 1 deletion front-ms/src/store/modules/app/mutations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { api } from "@/api";
import { api } from "@/api/auth";

export function SET_USER(state, user) {
state.user = user;
Expand Down
X Tutup