fixing media URL

This commit is contained in:
Dimas Atmodjo 2024-11-19 23:02:04 +07:00
parent 1a5cddd922
commit 92ccf51cf2
14 changed files with 44 additions and 42 deletions

View File

@ -1,6 +1,6 @@
import { useState, useEffect, useRef } from 'react'; import { useState, useEffect, useRef } from 'react';
import exerciseService from '../services/serviceExercises'; import exerciseService from '../services/serviceExercises';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
function videoUrlChecker(url) { function videoUrlChecker(url) {
const youtubeRegex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/; const youtubeRegex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
@ -23,7 +23,7 @@ const useUpdateExercises = (levelId) => {
const [topicName, setTopicName] = useState('topic'); const [topicName, setTopicName] = useState('topic');
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const mediaPath = `${API_URL}/uploads/exercise`; const mediaPath = `${MEDIA_URL}/uploads/exercise`;
const [formData, setFormData] = useState({ const [formData, setFormData] = useState({
ID_ADMIN_EXERCISE: "", ID_ADMIN_EXERCISE: "",

View File

@ -1,7 +1,7 @@
import { useState, useEffect, useRef } from 'react'; import { useState, useEffect, useRef } from 'react';
import materialService from '../services/serviceMaterials'; import materialService from '../services/serviceMaterials';
import { ButtonView } from 'ckeditor5'; import { ButtonView } from 'ckeditor5';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useTest = (materialId) => { const useTest = (materialId) => {
const [editorData, setEditorData] = useState(''); const [editorData, setEditorData] = useState('');
@ -13,7 +13,7 @@ const useTest = (materialId) => {
const editorContainerRef = useRef(null); const editorContainerRef = useRef(null);
const editorRef = useRef(null); const editorRef = useRef(null);
const [isLayoutReady, setIsLayoutReady] = useState(false); const [isLayoutReady, setIsLayoutReady] = useState(false);
const mediaPath = `${API_URL}/uploads/level/`; const mediaPath = `${MEDIA_URL}/uploads/level/`;
const [show, setShow] = useState(false); const [show, setShow] = useState(false);

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import materialService from '../services/serviceMaterials'; import materialService from '../services/serviceMaterials';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useUpdateMaterials = (materialId) => { const useUpdateMaterials = (materialId) => {
const [materialData, setMaterialData] = useState([]); const [materialData, setMaterialData] = useState([]);
@ -9,7 +9,7 @@ const useUpdateMaterials = (materialId) => {
const [topicName, setTopicName] = useState('topic'); const [topicName, setTopicName] = useState('topic');
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const mediaPath = `${API_URL}/uploads/level`; const mediaPath = `${MEDIA_URL}/uploads/level`;
const [formData, setFormData] = useState({ const [formData, setFormData] = useState({
content: '', content: '',

View File

@ -1,9 +1,9 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import sectionService from '../services/serviceSections'; import sectionService from '../services/serviceSections';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useSections = () => { const useSections = () => {
const thumbPath = `${API_URL}/uploads/section/`; const thumbPath = `${MEDIA_URL}/uploads/section/`;
const [sections, setSections] = useState([]); const [sections, setSections] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);

View File

@ -102,12 +102,14 @@ const ManageSections = () => {
<td>{section.NAME_SECTION}</td> <td>{section.NAME_SECTION}</td>
<td>{section.DESCRIPTION_SECTION}</td> <td>{section.DESCRIPTION_SECTION}</td>
<td className='text-center action-col'> <td className='text-center action-col'>
<Button size='sm' className='btn-edit' onClick={() => handleShow(section)}> <div className="d-flex">
<i className="bi bi-pencil-square"></i> <Button size='sm' className='btn-edit' onClick={() => handleShow(section)}>
</Button> <i className="bi bi-pencil-square"></i>
<Button size='sm' className='btn-delete' onClick={() => deleteSection(section.ID_SECTION)}> </Button>
<i className="bi bi-trash3"></i> <Button size='sm' className='btn-delete' onClick={() => deleteSection(section.ID_SECTION)}>
</Button> <i className="bi bi-trash3"></i>
</Button>
</div>
</td> </td>
</tr> </tr>
)) ))

View File

@ -108,12 +108,14 @@ const ManageTopics = () => {
<td>{topic.NAME_TOPIC}</td> <td>{topic.NAME_TOPIC}</td>
<td>{topic.DESCRIPTION_TOPIC}</td> <td>{topic.DESCRIPTION_TOPIC}</td>
<td className='text-center action-col'> <td className='text-center action-col'>
<Button size='sm' className='btn-edit' onClick={() => handleShow(topic)}> <div class="d-flex">
<i className="bi bi-pencil-square"></i> <Button size='sm' className='btn-edit' onClick={() => handleShow(topic)}>
</Button> <i className="bi bi-pencil-square"></i>
<Button size='sm' className='btn-delete' onClick={() => deleteTopic(topic.ID_TOPIC)}> </Button>
<i className="bi bi-trash3"></i> <Button size='sm' className='btn-delete' onClick={() => deleteTopic(topic.ID_TOPIC)}>
</Button> <i className="bi bi-trash3"></i>
</Button>
</div>
</td> </td>
</tr> </tr>
)) ))

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import settingService from '../services/SettingService'; import settingService from '../services/SettingService';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useSettings = () => { const useSettings = () => {
const [profile, setProfile] = useState(null); const [profile, setProfile] = useState(null);
@ -10,7 +10,7 @@ const useSettings = () => {
const [loadingUpdate, setLoadingUpdate] = useState(false); const [loadingUpdate, setLoadingUpdate] = useState(false);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const thumbPath = `${API_URL}/uploads/avatar/`; const thumbPath = `${MEDIA_URL}/uploads/avatar/`;
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {

View File

@ -5,7 +5,7 @@ import { API_URL } from '../../../../utils/Constant';
// const login = async (EMAIL, PASSWORD) => { // const login = async (EMAIL, PASSWORD) => {
// try { // try {
// const response = await axios.post(`${API_URL}/api/login`, { EMAIL, PASSWORD }); // const response = await axios.post(`${API_URL}/login`, { EMAIL, PASSWORD });
// return response.data.payload; // return response.data.payload;
// } catch (error) { // } catch (error) {
// throw new Error(error.response?.data?.message || 'Login failed'); // throw new Error(error.response?.data?.message || 'Login failed');
@ -14,7 +14,7 @@ import { API_URL } from '../../../../utils/Constant';
const login = async (EMAIL, PASSWORD) => { const login = async (EMAIL, PASSWORD) => {
try { try {
const response = await axios.post(`${API_URL}/api/login`, { EMAIL, PASSWORD }, { const response = await axios.post(`${API_URL}/login`, { EMAIL, PASSWORD }, {
withCredentials: true withCredentials: true
}); });
const { TOKEN, refreshToken } = response.data.payload; const { TOKEN, refreshToken } = response.data.payload;
@ -25,7 +25,7 @@ const login = async (EMAIL, PASSWORD) => {
Authorization: TOKEN Authorization: TOKEN
} }
}; };
const data = await axios.get(`${API_URL}/api/getMe`, config); const data = await axios.get(`${API_URL}/getMe`, config);
const profile = data.data.payload; const profile = data.data.payload;
localStorage.setItem('userData', JSON.stringify({username: profile.NAME_USERS, picture: profile.PICTURE})); localStorage.setItem('userData', JSON.stringify({username: profile.NAME_USERS, picture: profile.PICTURE}));
@ -37,7 +37,7 @@ const login = async (EMAIL, PASSWORD) => {
const register = async (endpoint, data) => { const register = async (endpoint, data) => {
try { try {
const response = await axios.post(`${API_URL}/api/register/${endpoint}`, data); const response = await axios.post(`${API_URL}/register/${endpoint}`, data);
return response.data; return response.data;
} catch (error) { } catch (error) {
throw new Error(error.response?.data?.message || 'Registration failed'); throw new Error(error.response?.data?.message || 'Registration failed');
@ -46,7 +46,7 @@ const register = async (endpoint, data) => {
const forgotPassword = async (email) => { const forgotPassword = async (email) => {
try { try {
const response = await axios.post(`${API_URL}/api/forgot-password`, { email }); const response = await axios.post(`${API_URL}/forgot-password`, { email });
return response.data; return response.data;
} catch (error) { } catch (error) {
throw new Error(error.response?.data?.message || 'Password reset failed'); throw new Error(error.response?.data?.message || 'Password reset failed');
@ -60,7 +60,7 @@ const logout = () => {
const validateEmail = async (TOKEN) => { const validateEmail = async (TOKEN) => {
try { try {
const response = await axios.post(`${API_URL}/api/validateEmail`, { TOKEN }); const response = await axios.post(`${API_URL}/validateEmail`, { TOKEN });
return response.data; return response.data;
} catch (error) { } catch (error) {
throw new Error(error.response?.data?.message || 'Failed Validate'); throw new Error(error.response?.data?.message || 'Failed Validate');

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import settingService from '../services/SettingService'; import settingService from '../services/SettingService';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useSettings = () => { const useSettings = () => {
const [profile, setProfile] = useState(null); const [profile, setProfile] = useState(null);
@ -10,7 +10,7 @@ const useSettings = () => {
const [loadingUpdate, setLoadingUpdate] = useState(false); const [loadingUpdate, setLoadingUpdate] = useState(false);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const thumbPath = `${API_URL}/uploads/avatar/`; const thumbPath = `${MEDIA_URL}/uploads/avatar/`;
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {

View File

@ -1,12 +1,12 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import homeService from '../services/dashboardService'; import homeService from '../services/dashboardService';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useDashboards = () => { const useDashboards = () => {
const [journey, setJourney] = useState([]); const [journey, setJourney] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const thumbPath = `${API_URL}/uploads/section/`; const thumbPath = `${MEDIA_URL}/uploads/section/`;
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {

View File

@ -1,12 +1,12 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import learningService from '../services/learningService'; import learningService from '../services/learningService';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useSections = () => { const useSections = () => {
const [sections, setSections] = useState([]); const [sections, setSections] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const thumbPath = `${API_URL}/uploads/section/`; const thumbPath = `${MEDIA_URL}/uploads/section/`;
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import settingService from '../services/SettingService'; import settingService from '../services/SettingService';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
const useSettings = () => { const useSettings = () => {
const [profile, setProfile] = useState(null); const [profile, setProfile] = useState(null);
@ -10,7 +10,7 @@ const useSettings = () => {
const [loadingUpdate, setLoadingUpdate] = useState(false); const [loadingUpdate, setLoadingUpdate] = useState(false);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const thumbPath = `${API_URL}/uploads/avatar/`; const thumbPath = `${MEDIA_URL}/uploads/avatar/`;
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import topicService from '../services/topicService'; import topicService from '../services/topicService';
import { API_URL } from '../../../../utils/Constant'; import { MEDIA_URL } from '../../../../utils/Constant';
import { useSlugContext } from '../../../../utils/SlugContext'; import { useSlugContext } from '../../../../utils/SlugContext';
const useTopics = (sectionId) => { const useTopics = (sectionId) => {
@ -8,7 +8,7 @@ const useTopics = (sectionId) => {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const [sections, setSection] = useState(null); const [sections, setSection] = useState(null);
const thumbPath = `${API_URL}/uploads/section/`; const thumbPath = `${MEDIA_URL}/uploads/section/`;
const { sectionSlugMap } = useSlugContext(); const { sectionSlugMap } = useSlugContext();
useEffect(() => { useEffect(() => {

View File

@ -1,10 +1,8 @@
import axios from 'axios'; import axios from 'axios';
import { API_URL } from './Constant'; import { API_URL } from './Constant';
const URL_API = `${API_URL}/api`
const axiosInstance = axios.create({ const axiosInstance = axios.create({
baseURL: URL_API, baseURL: API_URL,
}); });
axiosInstance.interceptors.request.use( axiosInstance.interceptors.request.use(
@ -22,7 +20,7 @@ axiosInstance.interceptors.request.use(
const refreshAccessToken = async () => { const refreshAccessToken = async () => {
try { try {
const response = await axios.post(`${URL_API}/refreshToken`, {}, { withCredentials: true }); const response = await axios.post(`${API_URL}/refreshToken`, {}, { withCredentials: true });
const token = response.data.payload.TOKEN; const token = response.data.payload.TOKEN;
localStorage.setItem('token', token); localStorage.setItem('token', token);