Skip to content

Commit 254ba80

Browse files
committed
#14 Share and import photos
1 parent 6e8e54c commit 254ba80

File tree

9 files changed

+162
-95
lines changed

9 files changed

+162
-95
lines changed

package-lock.json

Lines changed: 36 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,15 @@
9696
},
9797
"dependencies": {
9898
"@capacitor/core": "1.0.0",
99-
"@ionic/core": "4.4.2",
99+
"@ionic/core": "4.5.0",
100100
"@sentry/browser": "5.4.0",
101-
"blueimp-load-image": "2.21.0",
102-
"browser-image-compression": "1.0.5",
101+
"blueimp-load-image": "2.22.0",
103102
"compressorjs": "1.0.5",
104103
"cors": "2.8.5",
105104
"electron-is-dev": "1.1.0",
106105
"electron-squirrel-startup": "^1.0.0",
107106
"is-electron": "^2.2.0",
108-
"js-file-downloader": "^1.1.0",
107+
"js-file-downloader": "^1.1.1",
109108
"jszip": "3.2.1",
110109
"localforage": "1.7.3",
111110
"uuid": "3.3.2"
@@ -124,16 +123,16 @@
124123
"@electron-forge/maker-zip": "6.0.0-beta.39",
125124
"@electron-forge/publisher-github": "6.0.0-beta.39",
126125
"@stencil/core": "0.18.1",
127-
"@types/jest": "24.0.13",
126+
"@types/jest": "24.0.14",
128127
"@types/puppeteer": "1.12.4",
129128
"blockstack": "19.2.1",
130-
"electron": "5.0.2",
131-
"husky": "2.4.0",
129+
"electron": "5.0.4",
130+
"husky": "2.4.1",
132131
"jest": "24.8.0",
133132
"jest-cli": "24.8.0",
134-
"nightwatch": "1.1.11",
135-
"prettier": "1.17.1",
136-
"pretty-quick": "1.11.0",
133+
"nightwatch": "1.1.12",
134+
"prettier": "1.18.2",
135+
"pretty-quick": "1.11.1",
137136
"puppeteer": "1.17.0",
138137
"rollup-plugin-node-builtins": "2.1.2",
139138
"rollup-plugin-node-globals": "1.4.0",

src/components.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import '@stencil/core';
99

1010
import '@ionic/core';
1111
import 'ionicons';
12-
import 'web-social-share';
1312
import {
1413
PhotoType,
1514
} from './models/photo-type';

src/models/photo-metadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ interface PhotoMetadata {
77
size: number;
88
uploadedDate: Date;
99
albums: string[];
10+
shared: boolean;
1011
}

src/pages/app-photo/app-photo.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,10 @@ export class AppPhoto {
523523
async shareOriginal(): Promise<void> {
524524
this.shareInProgress = true;
525525

526-
const metadata: PhotoMetadata = await PhotosService.getPhotoMetaData(
527-
this.photoId
528-
);
529-
const data = await PhotosService.loadPhoto(metadata, PhotoType.Download);
530-
PhotosService.uploadSharedPhoto(data, metadata);
531526
const appConfig = SettingsService.getAppConfig();
532527
const userSession = new blockstack.UserSession({ appConfig });
533528
const userData = userSession.loadUserData();
534-
const shareUrl = `${window.location.protocol}//${
535-
window.location.host
536-
}/#/shared/${userData.username}/${this.photoId}`;
529+
const shareUrl = `${window.location.protocol}//${window.location.host}/#/shared/${userData.username}/${this.photoId}`;
537530

538531
if (navigator && navigator.share) {
539532
await this.shareNative(shareUrl);
@@ -542,6 +535,15 @@ export class AppPhoto {
542535
await this.shareFallback(shareUrl);
543536
this.shareInProgress = false;
544537
}
538+
539+
const metadata: PhotoMetadata = await PhotosService.getPhotoMetaData(
540+
this.photoId
541+
);
542+
543+
if (!metadata.shared) {
544+
const data = await PhotosService.loadPhoto(metadata, PhotoType.Download);
545+
PhotosService.uploadSharedPhoto(data, metadata);
546+
}
545547
}
546548

547549
async shareNative(shareUrl: string) {

src/pages/app-shared/app-shared.tsx

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ declare var blockstack;
1717
export class AppShared {
1818
private present: PresentingService;
1919
private photoType: PhotoType = PhotoType.Download;
20+
private originalSource: any;
2021

2122
@Prop() photoId: string;
2223
@Prop() username: string;
@@ -26,6 +27,7 @@ export class AppShared {
2627
@State() importInProgress: boolean;
2728
@State() photo: any;
2829
@State() isUserSignedIn: boolean;
30+
@State() isUserTheSame: boolean;
2931

3032
constructor() {
3133
this.photo = {
@@ -38,8 +40,6 @@ export class AppShared {
3840
}
3941

4042
async componentWillLoad() {
41-
console.log('photoId', this.photoId);
42-
console.log('userId', this.username);
4343
const { Device } = Plugins;
4444
const info = await Device.getInfo();
4545
if (info.model === 'iPad') {
@@ -49,6 +49,11 @@ export class AppShared {
4949
const appConfig = SettingsService.getAppConfig();
5050
const userSession = new blockstack.UserSession({ appConfig });
5151
this.isUserSignedIn = userSession.isUserSignedIn();
52+
this.isUserTheSame =
53+
this.isUserSignedIn &&
54+
userSession.loadUserData().username === this.username
55+
? true
56+
: false;
5257

5358
await this.getPhoto(this.photoId);
5459
}
@@ -76,15 +81,17 @@ export class AppShared {
7681
rotation = metadata.stats.exifdata.tags.Orientation;
7782
}
7883

84+
this.originalSource = await PhotosService.loadPhoto(
85+
metadata,
86+
this.photoType,
87+
false,
88+
this.username,
89+
false
90+
);
91+
7992
if (rotation !== 1) {
8093
loadImage(
81-
await PhotosService.loadPhoto(
82-
metadata,
83-
this.photoType,
84-
false,
85-
this.username,
86-
false
87-
),
94+
this.originalSource,
8895
processedPhoto => {
8996
this.handleProcessedPhoto(processedPhoto);
9097
},
@@ -93,17 +100,10 @@ export class AppShared {
93100
}
94101
);
95102
} else {
96-
this.photo.source = await PhotosService.loadPhoto(
97-
metadata,
98-
this.photoType,
99-
false,
100-
this.username,
101-
false
102-
);
103103
this.photo = {
104104
photoId: this.photo.photoId,
105105
isLoaded: true,
106-
source: this.photo.source,
106+
source: this.originalSource,
107107
metadata: this.photo.metadata
108108
};
109109
}
@@ -153,7 +153,30 @@ export class AppShared {
153153
async importPhoto(event: MouseEvent) {
154154
event.preventDefault();
155155
this.importInProgress = true;
156-
await PhotosService.uploadPhoto(this.photo.metadata, this.photo.source);
156+
const fetchedData = await fetch(this.originalSource);
157+
const blob = await fetchedData.blob();
158+
const thumbnailData = await PhotosService.compressPhoto(
159+
blob,
160+
PhotoType.Thumbnail,
161+
this.photo.metadata.type
162+
);
163+
let viewerData = null;
164+
const { Device } = Plugins;
165+
const info = await Device.getInfo();
166+
if (info.model !== 'iPhone' && info.model !== 'iPad') {
167+
viewerData = await PhotosService.compressPhoto(
168+
blob,
169+
PhotoType.Viewer,
170+
this.photo.metadata.type
171+
);
172+
}
173+
await PhotosService.uploadPhoto(
174+
this.photo.metadata,
175+
this.photo.source,
176+
null,
177+
thumbnailData,
178+
viewerData
179+
);
157180
this.importInProgress = false;
158181
}
159182

@@ -184,7 +207,7 @@ export class AppShared {
184207
fill="outline"
185208
color="secondary"
186209
class="ion-hide-sm-down"
187-
hidden={!this.isUserSignedIn}
210+
hidden={!this.isUserSignedIn || this.isUserTheSame}
188211
disabled={this.downloadInProgress || this.importInProgress}
189212
onClick={event => this.importPhoto(event)}
190213
>

0 commit comments

Comments
 (0)