-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7052904
commit 2d68752
Showing
26 changed files
with
584 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: [siriusnottin] | ||
custom: ["https://buymeacoffee.com/siriusnottin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Coda.io | ||
.coda* | ||
_upload_build | ||
|
||
# Other | ||
*.paw | ||
|
||
# Logs | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# google-photos-api | ||
|
||
Google photos api client. | ||
|
||
This is a fork of [a PR that was never merged](https://github.com/roopakv/google-photos/pull/27). | ||
|
||
Link to the original repo: | ||
https://github.com/roopakv/google-photos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Transport } from "api/transport"; | ||
|
||
export class Albums { | ||
constructor(public transport: Transport) { } | ||
|
||
list(pageSize = 50, pageToken?: string) { // range: 20-50 | ||
return this.transport.get("albums", { pageSize, pageToken }); | ||
} | ||
|
||
get(albumId: string) { | ||
return this.transport.get(`albums/${albumId}`); | ||
} | ||
|
||
create(title: string, description?: string) { | ||
} | ||
|
||
share(albumId: string) { | ||
} | ||
|
||
unshare(albumId: string) { | ||
} | ||
|
||
addMediaItems(albumId: string, mediaItemIds: string[]) { | ||
} | ||
|
||
removeMediaItems(albumId: string, mediaItemIds: string[]) { | ||
} | ||
|
||
update(albumId: string, title: string, description?: string) { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { GDate } from "./gdate"; | ||
import { DateRange } from "./date-range"; | ||
|
||
export class DateFilter { | ||
public dates: ReturnType<typeof GDate.newDate>[] = []; | ||
public ranges: DateRange[] = []; | ||
|
||
addDate(date) { | ||
this.dates.push(GDate.newDate(date)); | ||
} | ||
|
||
addRange(startDate, endDate) { | ||
this.ranges.push(new DateRange(startDate, endDate)); | ||
} | ||
|
||
toJSON() { | ||
return { | ||
dates: this.dates.map(d => d.toJSON()), | ||
ranges: this.ranges.map(r => r.toJSON()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { GDate } from "./gdate"; | ||
import { MediaItemsFilter } from "types/api-types"; | ||
|
||
export class DateRange { | ||
constructor( | ||
public startDate: ReturnType<GDate['toJSON']> | GDate | Date, | ||
public endDate: ReturnType<GDate['toJSON']> | GDate | Date | ||
) { } | ||
|
||
toJSON(): MediaItemsFilter['dateFilter']['ranges'][0] { | ||
return { | ||
startDate: GDate.newDate(this.startDate).toJSON(), | ||
endDate: GDate.newDate(this.endDate).toJSON() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Moment, isMoment } from "moment"; | ||
import { GPhotosDate } from "types/api-types"; | ||
|
||
export class GDate { | ||
constructor(public year?: number, public month?: number, public day?: number) { } | ||
|
||
static fromDate(date: Date) { | ||
if (!(date instanceof Date)) { | ||
throw Error('Not a valid date object'); | ||
} | ||
return new GDate(date.getFullYear(), date.getMonth() + 1, date.getDate()); | ||
} | ||
|
||
static fromMoment(moment: Moment) { | ||
if (!isMoment(moment)) { | ||
throw Error('Not a valid moment object'); | ||
} | ||
return new GDate(moment.year(), moment.month() + 1, moment.date()); | ||
} | ||
|
||
static newDate(date?: GDate | Date | Moment | GPhotosDate) { | ||
if (date instanceof GDate) { | ||
return date; | ||
} | ||
if (date instanceof Date) { | ||
return GDate.fromDate(date); | ||
} | ||
if (isMoment(date)) { | ||
return GDate.fromMoment(date); | ||
} | ||
if (date.year && date.month && date.day) { | ||
return new GDate(date.year, date.month, date.day); | ||
} | ||
return new GDate(); | ||
} | ||
|
||
toJSON(): GPhotosDate { | ||
return { | ||
year: this.year, | ||
month: this.month, | ||
day: this.day | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as coda from "@codahq/packs-sdk"; | ||
|
||
import { Transport } from "./transport"; | ||
|
||
import { Albums } from "./albums"; | ||
import { MediaItems } from "./media-items"; | ||
|
||
import { DateFilter } from "./common/date-filter"; | ||
import { MediaTypeFilter } from "./media-items/media-type-filter"; | ||
import { FeatureFilter } from "./media-items/feature-filter" | ||
import { ContentFilter } from "./media-items/content-filter"; | ||
import { Filters } from "./media-items/filters"; | ||
export default class GPhotos { | ||
|
||
public readonly transport: Transport; | ||
|
||
public readonly albums: Albums; | ||
public readonly mediaItems: MediaItems; | ||
|
||
public readonly DateFilter = DateFilter; | ||
public readonly MediaTypeFilter = MediaTypeFilter; | ||
public readonly FeatureFilter = FeatureFilter; | ||
public readonly ContentFilter = ContentFilter; | ||
public readonly Filters = Filters; | ||
|
||
constructor(public readonly fetcher: coda.Fetcher) { | ||
this.transport = new Transport(fetcher); | ||
this.albums = new Albums(this.transport); | ||
this.mediaItems = new MediaItems(this.transport); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { MediasContentCategories } from 'types/api-types'; | ||
|
||
export class ContentFilter { | ||
|
||
public includedContentCategories: MediasContentCategories[] = [] | ||
public excludedContentCategories: MediasContentCategories[] = [] | ||
|
||
addIncludedCategory(category: MediasContentCategories) { | ||
this.includedContentCategories.push(category); | ||
} | ||
|
||
addExcludedCategory(category: MediasContentCategories) { | ||
this.excludedContentCategories.push(category); | ||
} | ||
|
||
toJSON() { | ||
return { | ||
includedContentCategories: this.includedContentCategories, | ||
excludedContentCategories: this.excludedContentCategories, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
import { MediaFeature, MediaItemsFilter } from "types/api-types"; | ||
|
||
export class FeatureFilter { | ||
public includedFeatures: [MediaFeature]; | ||
|
||
constructor(includedFeature = MediaFeature.None) { | ||
this.includedFeatures = [includedFeature]; | ||
} | ||
|
||
setFeature(feature: MediaFeature) { | ||
this.includedFeatures = [feature]; | ||
} | ||
|
||
toJSON(): MediaItemsFilter['featureFilter'] { | ||
return { | ||
includedFeatures: this.includedFeatures | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { DateFilter } from "../common/date-filter"; | ||
import { MediaTypeFilter } from "./media-type-filter"; | ||
import { ContentFilter } from "./content-filter"; | ||
import { MediaItemsFilter } from "types/api-types"; | ||
import { FeatureFilter } from "./feature-filter"; | ||
|
||
export class Filters { | ||
public dateFilter: DateFilter; | ||
public mediaTypeFilter: MediaTypeFilter; | ||
public contentFilter: ContentFilter; | ||
public featureFilter: FeatureFilter; | ||
|
||
constructor(public includeArchivedMedia = false) { } | ||
|
||
setDateFilter(dateFilter: DateFilter) { | ||
this.dateFilter = dateFilter; | ||
} | ||
|
||
setMediaTypeFilter(mediaTypeFilter: MediaTypeFilter) { | ||
this.mediaTypeFilter = mediaTypeFilter; | ||
} | ||
|
||
setContentFilter(contentFilter: ContentFilter) { | ||
this.contentFilter = contentFilter; | ||
} | ||
|
||
setIncludeArchivedMedia(includeArchivedMedia: boolean) { | ||
this.includeArchivedMedia = includeArchivedMedia; | ||
} | ||
|
||
setFeatureFilter(featureFilter: FeatureFilter) { | ||
this.featureFilter = featureFilter; | ||
} | ||
|
||
toJSON(): MediaItemsFilter { | ||
return { | ||
dateFilter: this.dateFilter, | ||
mediaTypeFilter: this.mediaTypeFilter, | ||
contentFilter: this.contentFilter, | ||
includeArchivedMedia: this.includeArchivedMedia, | ||
featureFilter: this.featureFilter, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Transport } from "api/transport"; | ||
import { Filters } from "./filters"; | ||
import { FetchResponse } from "@codahq/packs-sdk"; | ||
import { ApiResponse } from "types/api-types"; | ||
export class MediaItems { | ||
constructor(public transport: Transport) { } | ||
|
||
list(pageToken?: string, pageSize = 100) { // range: 25-100 | ||
return this.transport.get("mediaItems", { pageSize, pageToken }); | ||
} | ||
|
||
get(mediaItemId: string) { | ||
return this.transport.get(`mediaItems/${mediaItemId}`); | ||
} | ||
|
||
search(albumId: string, pageToken?: string, pageSize?: number, fields?: string): Promise<FetchResponse<ApiResponse>> | ||
search(filters: Filters, pageToken?: string, pageSize?: number, fields?: string): Promise<FetchResponse<ApiResponse>>; | ||
|
||
search(albumIdOrFilters: string | Filters, pageToken?: string, pageSize = 100, fields?: string) { | ||
const body: { | ||
pageSize?: number; | ||
pageToken?: string; | ||
albumId?: string; | ||
filters?: ReturnType<Filters["toJSON"]>; | ||
} = { pageSize, pageToken } | ||
if (typeof albumIdOrFilters === "string") { | ||
body.albumId = albumIdOrFilters; | ||
} else { | ||
body.filters = albumIdOrFilters.toJSON(); | ||
} | ||
return this.transport.post("mediaItems:search", { fields }, body); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MediaTypes, MediaItemsFilter } from 'types/api-types'; | ||
|
||
export class MediaTypeFilter { | ||
public mediaTypes: MediaTypes[]; | ||
|
||
constructor(type = MediaTypes.All) { | ||
this.mediaTypes = [type]; | ||
} | ||
|
||
setType(type: MediaTypes) { | ||
this.mediaTypes = [type]; | ||
} | ||
|
||
toJSON(): MediaItemsFilter['mediaTypeFilter'] { | ||
return { | ||
mediaTypes: this.mediaTypes | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Transport } from "api/transport"; | ||
|
||
export class SharedAlbums { | ||
constructor(public transport: Transport) { } | ||
|
||
list(pageSize = 50, pageToken?: string) { | ||
} | ||
|
||
get(id: string) { | ||
} | ||
|
||
join(id: string) { | ||
} | ||
|
||
leave(id: string) { | ||
} | ||
} |
Oops, something went wrong.