groups-js: initial s3 work

This commit is contained in:
Logan Allen 2020-04-23 22:59:39 -04:00
parent 9c6cb61d61
commit ff313fb720
5 changed files with 48 additions and 11 deletions

View File

@ -13,5 +13,6 @@
<script src="/~channel/channel.js"></script>
<script src="/~modulo/session.js"></script>
<script src="/~groups/js/index.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"></script>
</body>
</html>

View File

@ -6,6 +6,7 @@ import { Link } from 'react-router-dom';
import { EditElement } from '/components/lib/edit-element';
import { Spinner } from './icons/icon-spinner';
import { uxToHex } from '/lib/util';
import { S3Upload } from '/components/lib/s3-upload';
export class ContactCard extends Component {
constructor(props) {
@ -424,6 +425,7 @@ export class ContactCard extends Component {
<div className="w-100 mt8 flex justify-center pa4 pt8 pt0-l pa0-xl pt4-xl pb8">
<div className="w-100 mw6 tc">
{avatar}
<S3Upload s3Credentials={props.s3Credentials} />
<Sigil
ship={props.ship}
size={128}

View File

@ -0,0 +1,30 @@
import React, { Component } from 'react'
import S3Client from '/lib/s3';
export class S3Upload extends Component {
constructor(props) {
super(props);
console.log(props);
let credentials = props.s3Credentials.credentials;
let configuration = props.s3Credentials.configuration;
this.s3 = new S3Client();
this.s3.setCredentials(
credentials.endpoint,
credentials.accessKeyId,
credentials.secretAccessKey
);
window.s3 = this.s3;
}
componentDidUpdate(prevProps) {
const { props } = this;
console.log(props);
}
render() {
const { props } = this;
return <div></div>;
}
}

View File

@ -33,7 +33,9 @@ export class Root extends Component {
let defaultContacts =
(!!state.contacts && '/~/default' in state.contacts) ?
state.contacts['/~/default'] : {};
let groups = !!state.groups ? state.groups : {};
let s3Credentials = !!state.s3 ? state.s3 : {};
let invites =
(!!state.invites && '/contacts' in state.invites) ?
@ -211,6 +213,7 @@ export class Root extends Component {
ship={window.ship}
share={true}
rootIdentity={rootIdentity}
s3Credentials={s3Credentials}
/>
</Skeleton>
);
@ -259,6 +262,7 @@ export class Root extends Component {
path={groupPath}
ship={props.match.params.contact}
rootIdentity={rootIdentity}
s3Credentials={s3Credentials}
/>
</Skeleton>
);
@ -283,6 +287,7 @@ export class Root extends Component {
path="/~/default"
contact={me}
ship={window.ship}
s3Credentials={s3Credentials}
/>
</Skeleton>
);

View File

@ -1,23 +1,24 @@
const AWS = require('aws-sdk')
class S3 {
export default class S3Client {
constructor() {
this.endpoint = new AWS.Endpoint("");
this.s3 = null;
this.AWS = window.AWS;
this.endpoint = new this.AWS.Endpoint("");
this.accessKeyId = "";
this.secretAccesskey = "";
this.s3 = null;
}
setCredentials(endpoint, accessKeyId, secretAccessKey) {
this.endpoint = new AWS.Endpoint(endpoint);
this.AWS = window.AWS;
this.endpoint = new this.AWS.Endpoint(endpoint);
this.accessKeyId = accessKeyId;
this.secretAccessKey = secretAccessKey;
this.s3 =
new AWS.S3({
new this.AWS.S3({
endpoint: this.endpoint,
credentials: new AWS.Credentials({
credentials: new this.AWS.Credentials({
accessKeyId: this.accessKeyId,
secretAccessKey: this.secretAccessKey
})
@ -83,5 +84,3 @@ class S3 {
}
}
export let s3 = new S3();