Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tlon hosting upload method #2906

Merged
merged 8 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
24 changes: 13 additions & 11 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"@tloncorp/mock-http-api": "^1.2.0",
"@types/marked": "^4.3.0",
"@urbit/api": "^2.2.0",
"@urbit/aura": "^0.4.0",
"@urbit/aura": "^1.0.0",
"@urbit/http-api": "^3.0.0",
"@urbit/sigil-js": "^2.1.0",
"any-ascii": "^0.3.1",
Expand Down
2 changes: 2 additions & 0 deletions ui/src/state/storage/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const configuration = (json: S3Update, state: StorageState): StorageState => {
buckets: new Set(data.buckets),
currentBucket: data.currentBucket,
region: data.region,
presignedUrl: data.presignedUrl,
service: data.service,
};
}
return state;
Expand Down
3 changes: 2 additions & 1 deletion ui/src/state/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export const useStorage = createState<BaseStorageState>(
'Storage',
() => ({
loaded: false,
hasCredentials: false,
s3: {
configuration: {
buckets: new Set(),
currentBucket: '',
region: '',
presignedUrl: '',
service: 'credentials',
},
credentials: null,
},
Expand Down
101 changes: 88 additions & 13 deletions ui/src/state/storage/type.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import { S3Credentials } from '@urbit/api';
import { S3Client } from '@aws-sdk/client-s3';
import { Status } from '@/logic/status';

export interface GcpToken {
accessKey: string;
expiresIn: number;
export type StorageService = 'presigned-url' | 'credentials';

export interface StorageConfiguration {
buckets: Set<string>;
currentBucket: string;
region: string;
presignedUrl: string;
service: StorageService;
}

export interface StorageCredentials {
endpoint: string;
accessKeyId: string;
secretAccessKey: string;
}

export interface BaseStorageState {
loaded?: boolean;
hasCredentials?: boolean;
s3: {
configuration: {
buckets: Set<string>;
currentBucket: string;
region: string;
};
credentials: S3Credentials | null;
configuration: StorageConfiguration;
credentials: StorageCredentials | null;
};
[ref: string]: unknown;
}

export interface GcpToken {
accessKey: string;
expiresIn: number;
}

export interface FileStoreFile {
key: string;
file: File;
Expand Down Expand Up @@ -57,14 +68,18 @@ export interface FileStore {
client: S3Client | null;
uploaders: Record<string, Uploader>;
getUploader: (key: string) => Uploader;
createClient: (s3: S3Credentials, region: string) => void;
createClient: (s3: StorageCredentials, region: string) => void;
update: (key: string, updateFn: (uploader: Uploader) => void) => void;
uploadFiles: (
uploader: string,
files: FileList | File[] | null,
bucket: string
config: StorageConfiguration
) => Promise<void>;
upload: (
uploader: string,
upload: Upload,
config: StorageConfiguration
) => Promise<void>;
upload: (uploader: string, upload: Upload, bucket: string) => Promise<void>;
clear: (uploader: string) => void;
setUploadType: (uploaderKey: string, type: Uploader['uploadType']) => void;
getUploadType: (uploaderKey: string) => Uploader['uploadType'];
Expand All @@ -82,3 +97,63 @@ export interface UploadInputProps {
multiple?: boolean;
id: string;
}

export interface StorageUpdateCredentials {
credentials: StorageCredentials;
}

export interface StorageUpdateConfiguration {
configuration: {
buckets: string[];
currentBucket: string;
};
}

export interface StorageUpdateCurrentBucket {
setCurrentBucket: string;
}

export interface StorageUpdateAddBucket {
addBucket: string;
}

export interface StorageUpdateRemoveBucket {
removeBucket: string;
}

export interface StorageUpdateEndpoint {
setEndpoint: string;
}

export interface StorageUpdateAccessKeyId {
setAccessKeyId: string;
}

export interface StorageUpdateSecretAccessKey {
setSecretAccessKey: string;
}

export interface StorageUpdateRegion {
setRegion: string;
}

export interface StorageUpdateToggleService {
toggleService: string;
}

export interface StorageUpdateSetPresignedUrl {
setPresignedUrl: string;
}

export declare type StorageUpdate =
| StorageUpdateCredentials
| StorageUpdateConfiguration
| StorageUpdateCurrentBucket
| StorageUpdateAddBucket
| StorageUpdateRemoveBucket
| StorageUpdateEndpoint
| StorageUpdateAccessKeyId
| StorageUpdateSecretAccessKey
| StorageUpdateRegion
| StorageUpdateToggleService
| StorageUpdateSetPresignedUrl;
Loading
Loading