-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBacktraceFileAttachment.ts
More file actions
42 lines (38 loc) · 1.35 KB
/
BacktraceFileAttachment.ts
File metadata and controls
42 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { type BacktraceAttachment } from '@backtrace/sdk-core';
import { NativeModules, Platform } from 'react-native';
import type { ReactNativeFileProvider } from '../storage';
import { type FileLocation } from '../types/FileLocation';
export class BacktraceFileAttachment implements BacktraceAttachment<FileLocation> {
private readonly _fileSystemProvider: ReactNativeFileProvider = NativeModules.BacktraceFileSystemProvider;
public readonly name: string;
public readonly mimeType: string;
private readonly _uploadUri: string;
constructor(
public readonly filePath: string,
name?: string,
mimeType?: string,
) {
this.name = name ?? filePath;
this.mimeType = mimeType ?? 'application/octet-stream';
this._uploadUri = Platform.OS === 'android' ? `file://${this.filePath}` : this.filePath;
}
public get(): FileLocation | undefined {
const exists = this._fileSystemProvider.existsSync(this.filePath);
if (!exists) {
return undefined;
}
return {
uri: this._uploadUri,
name: this.name,
filename: this.name,
type: this.mimeType,
filepath: this.filePath,
};
}
public toJSON() {
return {
filePath: this.filePath,
name: this.name,
};
}
}