"use strict";exports.id=23840,exports.ids=[23840],exports.modules={923840:(a,b,c)=>{c.d(b,{syncGooglePhotos:()=>f});var d=c(425014),e=c(693349);async function f(a){let b=a.maxPages??10,c=await g(),e=c["Avatar URL"];if(!e)return{photosWritten:0,contactsSeen:0,reachedEnd:!0};let f=c["Email Address"];if(!f)return{photosWritten:0,contactsSeen:0,reachedEnd:!0};let j=await h(f),k=await (0,d.aR)({toolkitSlug:"gmail",preferredSlugs:["GMAIL_GET_PEOPLE"],signal:a.signal}),l=null,m=0,n=0,o=!1;for(let c=0;c<b;c+=1){let b;if(a.signal?.aborted)break;try{b=await (0,d.Rd)({toolSlug:k,connectedAccountId:a.connectionId,arguments:{other_contacts:!0,page_size:500,page_token:l??"",sources:["READ_SOURCE_TYPE_CONTACT","READ_SOURCE_TYPE_PROFILE"],person_fields:"emailAddresses,photos,metadata"},signal:a.signal,context:"gmail-get-people"})}catch(a){if(a instanceof d.Tf)return{photosWritten:m,contactsSeen:n,reachedEnd:!0};throw a}let f=b.data?.data??b.data,g=function(a){if(Array.isArray(a))return a;if(!a||"object"!=typeof a)return[];let b=a.other_contacts;if(b&&"object"==typeof b){let a=b.otherContacts;if(Array.isArray(a))return a}return Array.isArray(a.otherContacts)?a.otherContacts:Array.isArray(a.connections)?a.connections:[]}(f),h=[];for(let a of g){n+=1;let b=function(a){if(0===a.length)return null;let b=a=>"PROFILE"===a||"DOMAIN_PROFILE"===a||"CONTACT"===a;for(let c of a)if(c.url&&!c.default&&b(c.metadata?.source?.type))return c.url;for(let b of a)if(b.url&&!b.default)return b.url;return null}(a.photos??[]);if(!b)continue;let c=(a.emailAddresses??[]).map(a=>"string"==typeof a.value?a.value.toLowerCase().trim():"").filter(a=>a.length>0);if(0!==c.length)for(let a of c){let c=j.get(a);c&&h.push({entryId:c,avatarUrl:b})}}h.length>0&&(m+=await i({avatarFieldId:e,updates:h})),a.onProgress?.({page:c+1,photosWritten:m});let p=function(a){if(!a||"object"!=typeof a)return null;let b=a.other_contacts;if(b&&"object"==typeof b){let a=b.nextPageToken;if("string"==typeof a&&a.length>0)return a}let c=a.nextPageToken;return"string"==typeof c&&c.length>0?c:null}(f);if(!p){o=!0;break}l=p}return{photosWritten:m,contactsSeen:n,reachedEnd:o}}async function g(){let a=await (0,e.b2)("SELECT name, id FROM fields WHERE object_id = 'seed_obj_people_00000000000000'","name"),b={};for(let c of a)c.name&&c.id&&(b[c.name]=c.id);return b}async function h(a){let b=new Map;for(let c of(await (0,e.b2)(`SELECT entry_id, value FROM entry_fields WHERE field_id = '${a}'`))){if(!c.value)continue;let a=c.value.toLowerCase().trim();a&&b.set(a,c.entry_id)}return b}async function i(a){if(0===a.updates.length)return 0;let b=["BEGIN;"];for(let{entryId:c,avatarUrl:d}of a.updates){let e=c.replace(/'/g,"''"),f=d.replace(/'/g,"''");b.push(`DELETE FROM entry_fields WHERE entry_id = '${e}' AND field_id = '${a.avatarFieldId}';`),b.push(`INSERT INTO entry_fields (entry_id, field_id, value) VALUES ('${e}', '${a.avatarFieldId}', '${f}');`)}return b.push("COMMIT;"),await (0,e.L1)(b.join("\n"))?a.updates.length:0}d.kj}};