interface: thread gcp through props

Basically just a grep for 's3', and I added gcp wherever it looked like
I ought to.
This commit is contained in:
J 2021-02-26 00:38:01 +00:00
parent 11a58115b0
commit 1c0d8e524e
19 changed files with 59 additions and 59 deletions

View File

@ -1,41 +0,0 @@
import S3 from 'aws-sdk/clients/s3';
export default class S3Client {
constructor() {
this.s3 = null;
this.endpoint = '';
this.accessKeyId = '';
this.secretAccesskey = '';
}
setCredentials(endpoint, accessKeyId, secretAccessKey) {
this.endpoint = endpoint;
this.accessKeyId = accessKeyId;
this.secretAccessKey = secretAccessKey;
this.s3 = new S3({
endpoint: endpoint,
credentials: {
accessKeyId: this.accessKeyId,
secretAccessKey: this.secretAccessKey
}
});
}
async upload(bucket, filename, buffer) {
const params = {
Bucket: bucket,
Key: filename,
Body: buffer,
ACL: 'public-read',
ContentType: buffer.type
};
if(!this.s3) {
throw new Error('S3 not initialized');
}
return this.s3.upload(params).promise();
}
}

View File

@ -34,8 +34,8 @@ export function LinkResource(props: LinkResourceProps) {
associations, associations,
graphKeys, graphKeys,
unreads, unreads,
s3,
gcp, gcp,
s3,
history history
} = props; } = props;

View File

@ -114,15 +114,15 @@ export function EditProfile(props: any) {
<Input id="nickname" label="Name" mb={3} /> <Input id="nickname" label="Name" mb={3} />
<Col width="100%"> <Col width="100%">
<Text mb={2}>Description</Text> <Text mb={2}>Description</Text>
<MarkdownField id="bio" mb={3} s3={props.s3} /> <MarkdownField id="bio" mb={3} gcp={props.gcp} s3={props.s3} />
</Col> </Col>
<ColorInput id="color" label="Sigil Color" mb={3} /> <ColorInput id="color" label="Sigil Color" mb={3} />
<Row mb={3} width="100%"> <Row mb={3} width="100%">
<Col pr={2} width="50%"> <Col pr={2} width="50%">
<ImageInput id="cover" label="Cover Image" s3={props.s3} /> <ImageInput id="cover" label="Cover Image" gcp={props.gcp} s3={props.s3} />
</Col> </Col>
<Col pl={2} width="50%"> <Col pl={2} width="50%">
<ImageInput id="avatar" label="Profile Image" s3={props.s3} /> <ImageInput id="avatar" label="Profile Image" gcp={props.gcp} s3={props.s3} />
</Col> </Col>
</Row> </Row>
<Checkbox mb={3} id="isPublic" label="Public Profile" /> <Checkbox mb={3} id="isPublic" label="Public Profile" />

View File

@ -107,6 +107,7 @@ export function Profile(props: any) {
<EditProfile <EditProfile
ship={ship} ship={ship}
contact={contact} contact={contact}
gcp={props.gcp}
s3={props.s3} s3={props.s3}
api={props.api} api={props.api}
groups={props.groups} groups={props.groups}

View File

@ -50,6 +50,7 @@ export default function ProfileScreen(props: any) {
groups={props.groups} groups={props.groups}
contact={contact} contact={contact}
api={props.api} api={props.api}
gcp={props.gcp}
s3={props.s3} s3={props.s3}
isEdit={isEdit} isEdit={isEdit}
isPublic={isPublic} isPublic={isPublic}

View File

@ -37,6 +37,7 @@ export function PublishResource(props: PublishResourceProps) {
location={props.location} location={props.location}
unreads={props.unreads} unreads={props.unreads}
graphs={props.graphs} graphs={props.graphs}
gcp={props.gcp}
s3={props.s3} s3={props.s3}
/> />
</Box> </Box>

View File

@ -4,7 +4,7 @@ import { PostFormSchema, PostForm } from "./NoteForm";
import { FormikHelpers } from "formik"; import { FormikHelpers } from "formik";
import GlobalApi from "~/logic/api/global"; import GlobalApi from "~/logic/api/global";
import { RouteComponentProps, useLocation } from "react-router-dom"; import { RouteComponentProps, useLocation } from "react-router-dom";
import { GraphNode, TextContent, Association, S3State } from "~/types"; import { GraphNode, TextContent, Association, GcpState, S3State } from "~/types";
import { getLatestRevision, editPost } from "~/logic/lib/publish"; import { getLatestRevision, editPost } from "~/logic/lib/publish";
import {useWaitForProps} from "~/logic/lib/useWaitForProps"; import {useWaitForProps} from "~/logic/lib/useWaitForProps";
interface EditPostProps { interface EditPostProps {
@ -13,11 +13,12 @@ interface EditPostProps {
note: GraphNode; note: GraphNode;
api: GlobalApi; api: GlobalApi;
book: string; book: string;
gcp: GcpState;
s3: S3State; s3: S3State;
} }
export function EditPost(props: EditPostProps & RouteComponentProps) { export function EditPost(props: EditPostProps & RouteComponentProps) {
const { note, book, noteId, api, ship, history, s3 } = props; const { note, book, noteId, api, ship, history, gcp, s3 } = props;
const [revNum, title, body] = getLatestRevision(note); const [revNum, title, body] = getLatestRevision(note);
const location = useLocation(); const location = useLocation();
@ -54,6 +55,7 @@ export function EditPost(props: EditPostProps & RouteComponentProps) {
cancel cancel
history={history} history={history}
onSubmit={onSubmit} onSubmit={onSubmit}
gcp={gcp}
s3={s3} s3={s3}
submitLabel="Update" submitLabel="Update"
loadingText="Updating..." loadingText="Updating..."

View File

@ -6,6 +6,7 @@ import { MarkdownEditor } from "./MarkdownEditor";
export const MarkdownField = ({ export const MarkdownField = ({
id, id,
gcp,
s3, s3,
...rest ...rest
}: { id: string } & Parameters<typeof Box>[0]) => { }: { id: string } & Parameters<typeof Box>[0]) => {
@ -35,6 +36,7 @@ export const MarkdownField = ({
onBlur={handleBlur} onBlur={handleBlur}
value={value} value={value}
onChange={setValue} onChange={setValue}
gcp={gcp}
s3={s3} s3={s3}
/> />
<ErrorLabel mt="2" hasError={!!(error && touched)}> <ErrorLabel mt="2" hasError={!!(error && touched)}>

View File

@ -9,7 +9,7 @@ import {
import { AsyncButton } from "../../../components/AsyncButton"; import { AsyncButton } from "../../../components/AsyncButton";
import { Formik, Form, FormikHelpers } from "formik"; import { Formik, Form, FormikHelpers } from "formik";
import { MarkdownField } from "./MarkdownField"; import { MarkdownField } from "./MarkdownField";
import { S3State } from "~/types"; import { GcpState, S3State } from "~/types";
interface PostFormProps { interface PostFormProps {
initial: PostFormSchema; initial: PostFormSchema;
@ -21,6 +21,7 @@ interface PostFormProps {
) => Promise<any>; ) => Promise<any>;
submitLabel: string; submitLabel: string;
loadingText: string; loadingText: string;
gcp: GcpState;
s3: S3State; s3: S3State;
} }
@ -35,7 +36,7 @@ export interface PostFormSchema {
} }
export function PostForm(props: PostFormProps) { export function PostForm(props: PostFormProps) {
const { initial, onSubmit, submitLabel, loadingText, s3, cancel, history } = props; const { initial, onSubmit, submitLabel, loadingText, gcp, s3, cancel, history } = props;
return ( return (
<Col width="100%" height="100%" p={[2, 4]}> <Col width="100%" height="100%" p={[2, 4]}>
@ -66,7 +67,7 @@ export function PostForm(props: PostFormProps) {
type="button">Cancel</Button>} type="button">Cancel</Button>}
</Row> </Row>
</Row> </Row>
<MarkdownField flexGrow={1} id="body" s3={s3} /> <MarkdownField flexGrow={1} id="body" gcp={gcp} s3={s3} />
</Form> </Form>
</Formik> </Formik>
</Col> </Col>

View File

@ -6,7 +6,15 @@ import { RouteComponentProps } from "react-router-dom";
import Note from "./Note"; import Note from "./Note";
import { EditPost } from "./EditPost"; import { EditPost } from "./EditPost";
import { GraphNode, Graph, Contacts, Association, S3State, Group } from "~/types"; import {
GraphNode,
Graph,
Contacts,
Association,
GcpState,
S3State,
Group
} from "~/types";
interface NoteRoutesProps { interface NoteRoutesProps {
ship: string; ship: string;
@ -20,6 +28,7 @@ interface NoteRoutesProps {
baseUrl?: string; baseUrl?: string;
rootUrl?: string; rootUrl?: string;
group: Group; group: Group;
gcp: GcpState;
s3: S3State; s3: S3State;
} }

View File

@ -9,6 +9,7 @@ import {
Contacts, Contacts,
Rolodex, Rolodex,
Unreads, Unreads,
GcpState,
S3State S3State
} from "~/types"; } from "~/types";
import { Center, LoadingSpinner } from "@tlon/indigo-react"; import { Center, LoadingSpinner } from "@tlon/indigo-react";
@ -33,6 +34,7 @@ interface NotebookRoutesProps {
rootUrl: string; rootUrl: string;
association: Association; association: Association;
associations: Associations; associations: Associations;
gcp: GcpState;
s3: S3State; s3: S3State;
} }
@ -80,6 +82,7 @@ export function NotebookRoutes(
association={props.association} association={props.association}
graph={graph} graph={graph}
baseUrl={baseUrl} baseUrl={baseUrl}
gcp={props.gcp}
s3={props.s3} s3={props.s3}
/> />
)} )}
@ -112,6 +115,7 @@ export function NotebookRoutes(
contacts={notebookContacts} contacts={notebookContacts}
association={props.association} association={props.association}
group={group} group={group}
gcp={props.gcp}
s3={props.s3} s3={props.s3}
{...routeProps} {...routeProps}
/> />

View File

@ -6,7 +6,7 @@ import { RouteComponentProps } from "react-router-dom";
import { PostForm, PostFormSchema } from "./NoteForm"; import { PostForm, PostFormSchema } from "./NoteForm";
import {createPost} from "~/logic/api/graph"; import {createPost} from "~/logic/api/graph";
import {Graph} from "~/types/graph-update"; import {Graph} from "~/types/graph-update";
import {Association, S3State} from "~/types"; import {Association, GcpState, S3State} from "~/types";
import {newPost} from "~/logic/lib/publish"; import {newPost} from "~/logic/lib/publish";
interface NewPostProps { interface NewPostProps {
@ -16,6 +16,7 @@ interface NewPostProps {
graph: Graph; graph: Graph;
association: Association; association: Association;
baseUrl: string; baseUrl: string;
gcp: GcpState;
s3: S3State; s3: S3State;
} }
@ -53,6 +54,7 @@ export default function NewPost(props: NewPostProps & RouteComponentProps) {
onSubmit={onSubmit} onSubmit={onSubmit}
submitLabel="Publish" submitLabel="Publish"
loadingText="Posting..." loadingText="Posting..."
gcp={props.gcp}
s3={props.s3} s3={props.s3}
/> />
); );

View File

@ -9,7 +9,7 @@ import {
} from "@tlon/indigo-react"; } from "@tlon/indigo-react";
import GlobalApi from "~/logic/api/global"; import GlobalApi from "~/logic/api/global";
import { S3State } from "~/types"; import { GcpState, S3State } from "~/types";
import { ImageInput } from "~/views/components/ImageInput"; import { ImageInput } from "~/views/components/ImageInput";
import {ColorInput} from "~/views/components/ColorInput"; import {ColorInput} from "~/views/components/ColorInput";
@ -19,11 +19,13 @@ export function BackgroundPicker({
bgType, bgType,
bgUrl, bgUrl,
api, api,
gcp,
s3, s3,
}: { }: {
bgType: BgType; bgType: BgType;
bgUrl?: string; bgUrl?: string;
api: GlobalApi; api: GlobalApi;
gcp: GcpState;
s3: S3State; s3: S3State;
}) { }) {
@ -38,6 +40,7 @@ export function BackgroundPicker({
<ImageInput <ImageInput
ml="3" ml="3"
api={api} api={api}
gcp={gcp}
s3={s3} s3={s3}
id="bgUrl" id="bgUrl"
name="bgUrl" name="bgUrl"

View File

@ -10,7 +10,7 @@ import * as Yup from 'yup';
import GlobalApi from '~/logic/api/global'; import GlobalApi from '~/logic/api/global';
import { uxToHex } from '~/logic/lib/util'; import { uxToHex } from '~/logic/lib/util';
import { S3State, BackgroundConfig } from '~/types'; import { GcpState, S3State, BackgroundConfig } from '~/types';
import { BackgroundPicker, BgType } from './BackgroundPicker'; import { BackgroundPicker, BgType } from './BackgroundPicker';
import useLocalState, { LocalState } from '~/logic/state/local'; import useLocalState, { LocalState } from '~/logic/state/local';
@ -34,11 +34,12 @@ interface FormSchema {
interface DisplayFormProps { interface DisplayFormProps {
api: GlobalApi; api: GlobalApi;
gcp: GcpState;
s3: S3State; s3: S3State;
} }
export default function DisplayForm(props: DisplayFormProps) { export default function DisplayForm(props: DisplayFormProps) {
const { api, s3 } = props; const { api, gcp, s3 } = props;
const { hideAvatars, hideNicknames, background, set: setLocalState } = useLocalState(); const { hideAvatars, hideNicknames, background, set: setLocalState } = useLocalState();
@ -94,6 +95,7 @@ export default function DisplayForm(props: DisplayFormProps) {
bgType={props.values.bgType} bgType={props.values.bgType}
bgUrl={props.values.bgUrl} bgUrl={props.values.bgUrl}
api={api} api={api}
gcp={gcp}
s3={s3} s3={s3}
/> />
<Checkbox <Checkbox

View File

@ -13,6 +13,7 @@ type ProfileProps = StoreState & { api: GlobalApi; ship: string };
export default function Settings({ export default function Settings({
api, api,
gcp,
s3 s3
}: ProfileProps) { }: ProfileProps) {
return ( return (
@ -27,6 +28,7 @@ export default function Settings({
> >
<DisplayForm <DisplayForm
api={api} api={api}
gcp={gcp}
s3={s3} s3={s3}
/> />
<RemoteContentForm api={api} /> <RemoteContentForm api={api} />

View File

@ -22,7 +22,7 @@ import { ColorInput } from "~/views/components/ColorInput";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import { uxToHex } from "~/logic/lib/util"; import { uxToHex } from "~/logic/lib/util";
import {S3State} from "~/types"; import {GcpState, S3State} from "~/types";
import {ImageInput} from "~/views/components/ImageInput"; import {ImageInput} from "~/views/components/ImageInput";
interface FormSchema { interface FormSchema {
@ -46,11 +46,12 @@ interface GroupAdminSettingsProps {
group: Group; group: Group;
association: Association; association: Association;
api: GlobalApi; api: GlobalApi;
gcp: GcpState;
s3: S3State; s3: S3State;
} }
export function GroupAdminSettings(props: GroupAdminSettingsProps) { export function GroupAdminSettings(props: GroupAdminSettingsProps) {
const { group, association, s3 } = props; const { group, association, gcp, s3 } = props;
const { metadata } = association; const { metadata } = association;
const history = useHistory(); const history = useHistory();
const currentPrivate = "invite" in props.group.policy; const currentPrivate = "invite" in props.group.policy;
@ -132,6 +133,7 @@ export function GroupAdminSettings(props: GroupAdminSettingsProps) {
caption="A picture for your group" caption="A picture for your group"
placeholder="Enter URL" placeholder="Enter URL"
disabled={disabled} disabled={disabled}
gcp={gcp}
s3={s3} s3={s3}
/> />
<Checkbox <Checkbox

View File

@ -6,7 +6,7 @@ import GlobalApi from "~/logic/api/global";
import { GroupAdminSettings } from "./Admin"; import { GroupAdminSettings } from "./Admin";
import { GroupPersonalSettings } from "./Personal"; import { GroupPersonalSettings } from "./Personal";
import { GroupNotificationsConfig, S3State } from "~/types"; import { GroupNotificationsConfig, GcpState, S3State } from "~/types";
import { GroupChannelSettings } from "./Channels"; import { GroupChannelSettings } from "./Channels";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import {resourceFromPath, roleForShip} from "~/logic/lib/group"; import {resourceFromPath, roleForShip} from "~/logic/lib/group";
@ -21,6 +21,7 @@ interface GroupSettingsProps {
associations: Associations; associations: Associations;
api: GlobalApi; api: GlobalApi;
notificationsGroupConfig: GroupNotificationsConfig; notificationsGroupConfig: GroupNotificationsConfig;
gcp: GcpState;
s3: S3State; s3: S3State;
baseUrl: string; baseUrl: string;
} }

View File

@ -71,6 +71,7 @@ export function GroupsPane(props: GroupsPaneProps) {
association={groupAssociation!} association={groupAssociation!}
group={group!} group={group!}
api={api} api={api}
gcp={props.gcp}
s3={props.s3} s3={props.s3}
notificationsGroupConfig={props.notificationsGroupConfig} notificationsGroupConfig={props.notificationsGroupConfig}
associations={associations} associations={associations}

View File

@ -6,7 +6,12 @@ import { Contacts, Contact } from "~/types/contact-update";
import { Group } from "~/types/group-update"; import { Group } from "~/types/group-update";
import { Association } from "~/types/metadata-update"; import { Association } from "~/types/metadata-update";
import GlobalApi from "~/logic/api/global"; import GlobalApi from "~/logic/api/global";
import { GroupNotificationsConfig, S3State, Associations } from "~/types"; import {
GroupNotificationsConfig,
GcpState,
S3State,
Associations
} from "~/types";
import { GroupSettings } from "./GroupSettings/GroupSettings"; import { GroupSettings } from "./GroupSettings/GroupSettings";
import { Participants } from "./Participants"; import { Participants } from "./Participants";
@ -23,6 +28,7 @@ export function PopoverRoutes(
group: Group; group: Group;
association: Association; association: Association;
associations: Associations; associations: Associations;
gcp: GcpState;
s3: S3State; s3: S3State;
api: GlobalApi; api: GlobalApi;
notificationsGroupConfig: GroupNotificationsConfig; notificationsGroupConfig: GroupNotificationsConfig;
@ -127,6 +133,7 @@ export function PopoverRoutes(
api={props.api} api={props.api}
notificationsGroupConfig={props.notificationsGroupConfig} notificationsGroupConfig={props.notificationsGroupConfig}
associations={props.associations} associations={props.associations}
gcp={props.gcp}
s3={props.s3} s3={props.s3}
/> />
)} )}