add missing headers
This commit is contained in:
@@ -14,6 +14,10 @@ class ApiClient {
|
|||||||
this.accessToken = token;
|
this.accessToken = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAccessToken(): string | null {
|
||||||
|
return this.accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
private async request<T>(
|
private async request<T>(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
options: RequestInit = {},
|
options: RequestInit = {},
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import { useUpload } from '../hooks/useUpload';
|
|||||||
import { TagChip } from '../components/TagChip';
|
import { TagChip } from '../components/TagChip';
|
||||||
import { FileThumbnail } from '../components/FileThumbnail';
|
import { FileThumbnail } from '../components/FileThumbnail';
|
||||||
import { FileItem } from '../types';
|
import { FileItem } from '../types';
|
||||||
|
import { apiClient } from '../api/client';
|
||||||
|
import { ENDPOINTS } from '../constants/api';
|
||||||
|
|
||||||
const NUM_COLUMNS = 3;
|
const NUM_COLUMNS = 3;
|
||||||
const SCREEN_WIDTH = Dimensions.get('window').width;
|
const SCREEN_WIDTH = Dimensions.get('window').width;
|
||||||
@@ -132,8 +134,7 @@ export function FileEditScreen() {
|
|||||||
const imageUris: { uri: string }[] = [];
|
const imageUris: { uri: string }[] = [];
|
||||||
|
|
||||||
for (const fileId of targetIds) {
|
for (const fileId of targetIds) {
|
||||||
const response = await fetch(`${process.env.EXPO_PUBLIC_API_BASE_URL || 'http://192.168.1.17:8080/api/v1'}/files/${fileId}`);
|
const data = await apiClient.get<{ data: { url: string } }>(`${ENDPOINTS.FILES}/${fileId}`);
|
||||||
const data = await response.json();
|
|
||||||
const url = data?.data?.url;
|
const url = data?.data?.url;
|
||||||
if (url) {
|
if (url) {
|
||||||
imageUris.push({ uri: url });
|
imageUris.push({ uri: url });
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export function LoginScreen({ navigation }: any) {
|
|||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
placeholder="Nom d'utilisateur"
|
placeholder="Nom d'utilisateur"
|
||||||
|
placeholderTextColor="#999"
|
||||||
value={username}
|
value={username}
|
||||||
onChangeText={setUsername}
|
onChangeText={setUsername}
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
@@ -56,6 +57,7 @@ export function LoginScreen({ navigation }: any) {
|
|||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
placeholder="Mot de passe"
|
placeholder="Mot de passe"
|
||||||
|
placeholderTextColor="#999"
|
||||||
value={password}
|
value={password}
|
||||||
onChangeText={setPassword}
|
onChangeText={setPassword}
|
||||||
secureTextEntry
|
secureTextEntry
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export function RegisterScreen({ navigation }: any) {
|
|||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
placeholder="Nom d'utilisateur"
|
placeholder="Nom d'utilisateur"
|
||||||
|
placeholderTextColor="#999"
|
||||||
value={username}
|
value={username}
|
||||||
onChangeText={setUsername}
|
onChangeText={setUsername}
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
@@ -67,6 +68,7 @@ export function RegisterScreen({ navigation }: any) {
|
|||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
placeholder="Mot de passe"
|
placeholder="Mot de passe"
|
||||||
|
placeholderTextColor="#999"
|
||||||
value={password}
|
value={password}
|
||||||
onChangeText={setPassword}
|
onChangeText={setPassword}
|
||||||
secureTextEntry
|
secureTextEntry
|
||||||
@@ -76,6 +78,7 @@ export function RegisterScreen({ navigation }: any) {
|
|||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
placeholder="Confirmer le mot de passe"
|
placeholder="Confirmer le mot de passe"
|
||||||
|
placeholderTextColor="#999"
|
||||||
value={confirmPassword}
|
value={confirmPassword}
|
||||||
onChangeText={setConfirmPassword}
|
onChangeText={setConfirmPassword}
|
||||||
secureTextEntry
|
secureTextEntry
|
||||||
|
|||||||
@@ -15,11 +15,17 @@ export function useUpload() {
|
|||||||
const results = await Promise.allSettled(
|
const results = await Promise.allSettled(
|
||||||
files.map(async (file) => {
|
files.map(async (file) => {
|
||||||
const fsFile = new File(file.uri);
|
const fsFile = new File(file.uri);
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
const token = apiClient.getAccessToken();
|
||||||
|
if (token) {
|
||||||
|
headers['Authorization'] = `Bearer ${token}`;
|
||||||
|
}
|
||||||
const result = await fsFile.upload(`${API_BASE_URL}${ENDPOINTS.UPLOAD}`, {
|
const result = await fsFile.upload(`${API_BASE_URL}${ENDPOINTS.UPLOAD}`, {
|
||||||
httpMethod: 'POST',
|
httpMethod: 'POST',
|
||||||
uploadType: UploadType.MULTIPART,
|
uploadType: UploadType.MULTIPART,
|
||||||
fieldName: 'file',
|
fieldName: 'file',
|
||||||
mimeType: file.type,
|
mimeType: file.type,
|
||||||
|
headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
|
|||||||
Reference in New Issue
Block a user