@churchapps/content-providers 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -17754,6 +17754,149 @@ var GoCurriculumProvider = class extends BaseProvider {
17754
17754
  }
17755
17755
  };
17756
17756
 
17757
+ // src/providers/googledrive/GoogleDriveProvider.ts
17758
+ var FOLDER_MIME = "application/vnd.google-apps.folder";
17759
+ var MAX_PAGINATION_CALLS2 = 10;
17760
+ var LEAF_CHECK_MAX_FOLDERS = 50;
17761
+ var GoogleDriveProvider = class extends BaseProvider {
17762
+ constructor() {
17763
+ super(...arguments);
17764
+ this.oauthHelper = new OAuthHelper();
17765
+ this.id = "googledrive";
17766
+ this.name = "Google Drive";
17767
+ this.logos = {
17768
+ light: "https://ssl.gstatic.com/images/branding/product/2x/drive_2020q4_48dp.png",
17769
+ dark: "https://ssl.gstatic.com/images/branding/product/2x/drive_2020q4_48dp.png"
17770
+ };
17771
+ this.config = {
17772
+ id: "googledrive",
17773
+ name: "Google Drive",
17774
+ apiBase: "https://www.googleapis.com/drive/v3",
17775
+ // Token endpoint host; the user-facing consent screen is accounts.google.com (see buildAuthUrlFromChallenge)
17776
+ oauthBase: "https://oauth2.googleapis.com",
17777
+ clientId: "214868247432-hao323qmsfu96h345udaifs8f1nc7i71.apps.googleusercontent.com",
17778
+ // Google requires client_secret even for PKCE public clients; injected server-side via setProviderSecret("googledrive", ...)
17779
+ get clientSecret() {
17780
+ return getProviderSecret("googledrive");
17781
+ },
17782
+ scopes: ["https://www.googleapis.com/auth/drive.readonly"]
17783
+ };
17784
+ this.requiresAuth = true;
17785
+ this.authTypes = ["oauth_pkce"];
17786
+ this.capabilities = {
17787
+ browse: true,
17788
+ playlist: true,
17789
+ instructions: true,
17790
+ mediaLicensing: false
17791
+ };
17792
+ }
17793
+ // Paths are Drive folder ids ("/<id>"), not names; root is "" or "/"
17794
+ folderIdFromPath(path) {
17795
+ const trimmed = (path || "").replace(/^\//, "");
17796
+ return trimmed || "root";
17797
+ }
17798
+ isValidId(id) {
17799
+ return /^[\w-]+$/.test(id);
17800
+ }
17801
+ async listFiles(query, auth) {
17802
+ if (!auth) {
17803
+ console.error("[GoogleDrive] No auth token provided");
17804
+ return [];
17805
+ }
17806
+ const all = [];
17807
+ let pageToken;
17808
+ for (let i = 0; i < MAX_PAGINATION_CALLS2; i++) {
17809
+ const params = new URLSearchParams({
17810
+ q: query,
17811
+ fields: "nextPageToken,files(id,name,mimeType,thumbnailLink,webContentLink,parents)",
17812
+ orderBy: "folder,name_natural",
17813
+ pageSize: "1000",
17814
+ supportsAllDrives: "true",
17815
+ includeItemsFromAllDrives: "true"
17816
+ });
17817
+ if (pageToken) params.set("pageToken", pageToken);
17818
+ const response = await this.apiRequest(`/files?${params.toString()}`, auth);
17819
+ if (!response) break;
17820
+ all.push(...response.files || []);
17821
+ pageToken = response.nextPageToken;
17822
+ if (!pageToken) break;
17823
+ }
17824
+ return all;
17825
+ }
17826
+ async childItems(folderId, auth) {
17827
+ const entries = await this.listFiles(`'${folderId}' in parents and trashed=false`, auth);
17828
+ const folders = entries.filter((e) => e.mimeType === FOLDER_MIME);
17829
+ const mediaFiles = entries.filter((e) => e.mimeType.startsWith("video/") || e.mimeType.startsWith("image/"));
17830
+ return { folders, mediaFiles };
17831
+ }
17832
+ /** One batched query marks which sibling folders have subfolders; null = unknown (isLeaf omitted). */
17833
+ async leafIds(folders, auth) {
17834
+ if (folders.length === 0 || folders.length > LEAF_CHECK_MAX_FOLDERS) return null;
17835
+ const parentClause = folders.map((f) => `'${f.id}' in parents`).join(" or ");
17836
+ const subfolders = await this.listFiles(`mimeType='${FOLDER_MIME}' and trashed=false and (${parentClause})`, auth);
17837
+ const parentsWithSubfolders = new Set(subfolders.flatMap((s) => s.parents || []));
17838
+ return new Set(folders.filter((f) => !parentsWithSubfolders.has(f.id)).map((f) => f.id));
17839
+ }
17840
+ toContentFile(file) {
17841
+ const url = file.webContentLink || `https://drive.google.com/uc?id=${file.id}&export=download`;
17842
+ return {
17843
+ type: "file",
17844
+ id: file.id,
17845
+ title: file.name,
17846
+ mediaType: detectMediaType(file.name, file.mimeType),
17847
+ thumbnail: file.thumbnailLink,
17848
+ url,
17849
+ downloadUrl: url
17850
+ };
17851
+ }
17852
+ async browse(path, auth) {
17853
+ const folderId = this.folderIdFromPath(path);
17854
+ if (!this.isValidId(folderId)) return [];
17855
+ const { folders, mediaFiles } = await this.childItems(folderId, auth);
17856
+ const leaves = await this.leafIds(folders, auth);
17857
+ const folderItems = folders.map((f) => ({ type: "folder", id: f.id, title: f.name, path: `/${f.id}`, isLeaf: leaves ? leaves.has(f.id) : void 0 }));
17858
+ return [...folderItems, ...mediaFiles.map((f) => this.toContentFile(f))];
17859
+ }
17860
+ async getPlaylist(path, auth, _resolution) {
17861
+ const folderId = this.folderIdFromPath(path);
17862
+ if (folderId === "root" || !this.isValidId(folderId)) return null;
17863
+ const { mediaFiles } = await this.childItems(folderId, auth);
17864
+ return mediaFiles.length > 0 ? mediaFiles.map((f) => this.toContentFile(f)) : null;
17865
+ }
17866
+ async getInstructions(path, auth) {
17867
+ const files = await this.getPlaylist(path, auth);
17868
+ if (!files) return null;
17869
+ const meta = await this.apiRequest(`/files/${this.folderIdFromPath(path)}?fields=name&supportsAllDrives=true`, auth);
17870
+ const folderName = meta?.name || "Google Drive";
17871
+ return filesToInstructions(folderName, files, { id: "googledrive-section", label: folderName });
17872
+ }
17873
+ generateCodeVerifier() {
17874
+ return this.oauthHelper.generateCodeVerifier();
17875
+ }
17876
+ async buildAuthUrl(codeVerifier, redirectUri, state) {
17877
+ const codeChallenge = await this.oauthHelper.generateCodeChallenge(codeVerifier);
17878
+ return { url: this.buildAuthUrlFromChallenge(codeChallenge, redirectUri, state || this.id), challengeMethod: "S256" };
17879
+ }
17880
+ buildAuthUrlFromChallenge(codeChallenge, redirectUri, state) {
17881
+ const params = new URLSearchParams({
17882
+ response_type: "code",
17883
+ client_id: this.config.clientId,
17884
+ redirect_uri: redirectUri,
17885
+ scope: this.config.scopes.join(" "),
17886
+ code_challenge: codeChallenge,
17887
+ code_challenge_method: "S256",
17888
+ // offline + consent so Google issues a refresh_token on every connect
17889
+ access_type: "offline",
17890
+ prompt: "consent",
17891
+ state
17892
+ });
17893
+ return `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`;
17894
+ }
17895
+ async exchangeCodeForTokens(code, codeVerifier, redirectUri) {
17896
+ return this.oauthHelper.exchangeCodeForTokens(this.config, this.id, code, codeVerifier, redirectUri);
17897
+ }
17898
+ };
17899
+
17757
17900
  // src/providers/index.ts
17758
17901
  var unimplementedProviders = [
17759
17902
  {
@@ -17795,6 +17938,7 @@ function initializeProviders() {
17795
17938
  new B1ChurchProvider(),
17796
17939
  new DropboxProvider(),
17797
17940
  new GoCurriculumProvider(),
17941
+ new GoogleDriveProvider(),
17798
17942
  new BibleProjectProvider(),
17799
17943
  new HighVoltageKidsProvider(),
17800
17944
  new JesusFilmProvider(),
@@ -17839,7 +17983,7 @@ function getAvailableProviders(ids) {
17839
17983
  }
17840
17984
 
17841
17985
  // src/index.ts
17842
- var VERSION = true ? "0.8.0" : "dev";
17986
+ var VERSION = true ? "0.9.1" : "dev";
17843
17987
  // Annotate the CommonJS export names for ESM import in node:
17844
17988
  0 && (module.exports = {
17845
17989
  APlayProvider,