mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00
Restructure repository (#426)
organized repository Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Philip Molares <git@molar.es>
This commit is contained in:
parent
66258ca615
commit
0fadc09f2b
254 changed files with 384 additions and 403 deletions
|
@ -1,6 +1,5 @@
|
|||
import { RegisterError } from '../components/landing/pages/register/register'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
import { RegisterError } from '../../components/register-page/register-page'
|
||||
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
|
||||
|
||||
export const doInternalLogin = async (username: string, password: string): Promise<void> => {
|
||||
const response = await fetch(getApiUrl() + '/auth/internal', {
|
|
@ -1,5 +1,4 @@
|
|||
import { expectResponseCode, getApiUrl } from '../../utils/apiUtils'
|
||||
import { defaultFetchConfig } from '../default'
|
||||
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
|
||||
import { Config } from './types'
|
||||
|
||||
export const getConfig = async (): Promise<Config> => {
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
export const defaultFetchConfig: Partial<RequestInit> = {
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
redirect: 'follow',
|
||||
referrerPolicy: 'no-referrer'
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { HistoryEntry } from '../components/landing/pages/history/history'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
|
||||
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
|
||||
import { HistoryEntry } from '../../components/history-page/history-page'
|
||||
|
||||
export const getHistory = async (): Promise<HistoryEntry[]> => {
|
||||
const response = await fetch(getApiUrl() + '/history')
|
|
@ -1,6 +1,5 @@
|
|||
import { LoginProvider } from '../redux/user/types'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
import { LoginProvider } from '../../redux/user/types'
|
||||
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
|
||||
|
||||
export const getMe = async (): Promise<meResponse> => {
|
||||
const response = await fetch(getApiUrl() + '/me', {
|
|
@ -1,6 +1,5 @@
|
|||
import { ImageProxyResponse } from '../components/editor/markdown-renderer/replace-components/image/types'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
import { ImageProxyResponse } from '../../components/markdown-renderer/replace-components/image/types'
|
||||
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
|
||||
|
||||
export const getProxiedUrl = async (imageUrl: string): Promise<ImageProxyResponse> => {
|
||||
const response = await fetch(getApiUrl() + '/media/proxy', {
|
|
@ -1,5 +1,4 @@
|
|||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
|
||||
|
||||
interface LastChange {
|
||||
userId: string
|
22
src/api/utils.ts
Normal file
22
src/api/utils.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { store } from '../redux'
|
||||
|
||||
export const defaultFetchConfig: Partial<RequestInit> = {
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
redirect: 'follow',
|
||||
referrerPolicy: 'no-referrer'
|
||||
}
|
||||
|
||||
export const getApiUrl = (): string => {
|
||||
return store.getState().apiUrl.apiUrl
|
||||
}
|
||||
|
||||
export const expectResponseCode = (response: Response, code = 200): void => {
|
||||
if (response.status !== code) {
|
||||
throw new Error(`response code is not ${code}`)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue