Skip to content

Commit

Permalink
Merge branch 'stage' into promptcard
Browse files Browse the repository at this point in the history
  • Loading branch information
TsayAdobe authored Sep 27, 2024
2 parents 50bfee8 + f0bdb54 commit 1b479f1
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 37 deletions.
4 changes: 2 additions & 2 deletions acrobat/blocks/verb-widget/limits.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const LIMITS = {
fillsign: {
maxFileSize: 100000000, // 1 MB
maxFileSizeFriendly: '100 MB', // 1 MB
maxFileSize: 100000000, // 100 MB
maxFileSizeFriendly: '100 MB', // 100 MB
acceptedFiles: ['application/pdf'],
maxNumFiles: 1,
mobileApp: true,
Expand Down
111 changes: 83 additions & 28 deletions acrobat/blocks/verb-widget/verb-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@ import verbAnalytics from '../../scripts/alloy/verb-widget.js';
const miloLibs = setLibs('/libs');
const { createTag } = await import(`${miloLibs}/utils/utils.js`);

const fallBack = 'https://www.adobe.com/go/acrobat-overview';
const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html';

const setUser = () => {
localStorage.setItem('unity.user', 'true');
const verbRedirMap = {
createpdf: 'createpdf',
'crop-pages': 'crop',
'delete-pages': 'deletepages',
'extract-pages': 'extract',
'combine-pdf': 'combine',
'protect-pdf': 'protect',
'add-comment': 'addcomment',
'pdf-to-image': 'pdftoimage',
'reorder-pages': 'reorderpages',
sendforsignature: 'sendforsignature',
'rotate-pages': 'rotatepages',
fillsign: 'fillsign',
'split-pdf': 'split',
'insert-pdf': 'insert',
'compress-pdf': 'compress',
'png-to-pdf': 'jpgtopdf',
'number-pages': 'number',
'ocr-pdf': 'ocr',
'chat-pdf': 'chat',
'chat-pdf-student': 'study',
};

const handleError = (err, errTxt, str, strTwo) => {
err.classList.add('verb-error');
err.classList.remove('hide');
errTxt.textContent = `${window.mph[str]} ${strTwo || ''}`;

setTimeout(() => {
err.classList.remove('verb-error');
err.classList.add('hide');
}, 5000);
const setUser = () => {
localStorage.setItem('unity.user', 'true');
};

const setDraggingClass = (widget, shouldToggle) => {
Expand Down Expand Up @@ -47,6 +60,19 @@ function initiatePrefetch(verb) {
}
}

function redDir(verb) {
const hostname = window?.location?.hostname;
const ENV = getEnv();
const VERB = verb;
let newLocation;
if (hostname !== 'www.adobe.com' && hostname !== 'sign.ing' && hostname !== 'edit.ing') {
newLocation = `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}-${ENV}`;
} else {
newLocation = `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}` || fallBack;
}
window.location.href = newLocation;
}

export default async function init(element) {
if (isOldBrowser()) {
window.location.href = EOLBrowserPage;
Expand Down Expand Up @@ -110,6 +136,21 @@ export default async function init(element) {

element.append(widget, footer);

// Redirect after IMS:Ready
window.addEventListener('IMS:Ready', () => {
console.log('IMS:Ready 😎');
if (window.adobeIMS.isSignedInUser()
&& window.adobeIMS.getAccountType() !== 'type1') {
redDir(VERB);
}
});
// Race Condition
if (window.adobeIMS?.isSignedInUser()
&& window.adobeIMS?.getAccountType() !== 'type1') {
console.log('Race Con ⏩');
redDir(VERB);
}

// Analytics
verbAnalytics('landing:shown', VERB);

Expand All @@ -121,6 +162,7 @@ export default async function init(element) {

button.addEventListener('click', () => {
verbAnalytics('filepicker:shown', VERB);
verbAnalytics('dropzone:choose-file-clicked', VERB);
initiatePrefetch(VERB);
});

Expand Down Expand Up @@ -150,7 +192,7 @@ export default async function init(element) {

window.addEventListener('unity:track-analytics', (e) => {
if (e.detail?.event === 'change') {
verbAnalytics('choose-file:open', VERB);
verbAnalytics('choose-file:open', VERB, e.detail?.data);
setUser();
}
// maybe new event name files-dropped?
Expand All @@ -159,10 +201,6 @@ export default async function init(element) {
setDraggingClass(widget, false);
setUser();
}
if (e.detail?.event === 'choose-file-clicked') {
verbAnalytics('dropzone:choose-file-clicked', VERB, e.detail?.data);
setUser();
}

if (e.detail?.event === 'uploading') {
verbAnalytics('job:uploading', VERB, e.detail?.data);
Expand All @@ -176,39 +214,56 @@ export default async function init(element) {
});

// Errors, Analytics & Logging
const handleError = (str) => {
errorState.classList.add('verb-error');
errorState.classList.remove('hide');
errorStateText.textContent = str;

setTimeout(() => {
errorState.classList.remove('verb-error');
errorState.classList.add('hide');
}, 5000);
};

window.addEventListener('unity:show-error-toast', (e) => {
// eslint-disable-next-line no-console
console.log(`⛔️ Error Code - ${e.detail?.code}`);

if (e.detail?.code === 'only_accept_one_file') {
handleError(errorState, errorStateText, 'verb-widget-error-multi');
if (e.detail?.code.includes('error_only_accept_one_file')) {
handleError(e.detail?.message);
verbAnalytics('error', VERB);
}

if (e.detail?.code === 'unsupported_type') {
handleError(errorState, errorStateText, 'verb-widget-error-unsupported');
if (e.detail?.code.includes('error_unsupported_type')) {
handleError(e.detail?.message);
verbAnalytics('error:unsupported_type', VERB);
}

if (e.detail?.code === 'empty_file') {
handleError(errorState, errorStateText, 'verb-widget-error-empty');
if (e.detail?.code.includes('error_empty_file')) {
handleError(e.detail?.message);
verbAnalytics('error:empty_file', VERB);
}

// Code may be wrong. should be 'file_too_large'
if (e.detail?.code === 'file_too_largempty_file') {
handleError(errorState, errorStateText, 'verb-widget-error-large', LIMITS[VERB].maxFileSizeFriendly);
if (e.detail?.code.includes('error_file_too_large')) {
handleError(e.detail?.message);
verbAnalytics('error', VERB);
}

if (e.detail?.code === 'max_page_count') {
handleError(errorState, errorStateText, 'verb-widget-error-max', LIMITS[VERB].maxNumFiles);
if (e.detail?.code.includes('error_max_page_count')) {
handleError(e.detail?.message);
verbAnalytics('error:max_page_count', VERB);
}

if (e.detail?.code.includes('error_generic')
|| e.detail?.code.includes('error_max_quota_exceeded')
|| e.detail?.code.includes('error_no_storage_provision')
|| e.detail?.code.includes('error_duplicate_asset')) {
handleError(e.detail?.message);
verbAnalytics('error', VERB);
}

// acrobat:verb-fillsign:error:page_count_missing_from_metadata_api
// acrobat:verb-fillsign:error:403
// acrobat:verb-fillsign:error
// LANA for 403
});
}
Expand Down
10 changes: 5 additions & 5 deletions acrobat/scripts/alloy/verb-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ if (params.dropzone2) {
appTags.push('dropzone2');
}

export default function init(eventName, verb) {
console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName}`);
export default function init(eventName, verb, metaData) {
console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName} - metaData: ${metaData?.type} / ${metaData?.size} `);
const event = {
documentUnloading: true,
data: {
Expand Down Expand Up @@ -66,10 +66,10 @@ export default function init(eventName, verb) {
dcweb2: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
size: '2-5MB',
type: metaData?.type,
size: metaData?.size,
count: 1,
extension: 'docx',
// extension: 'docx', may not be needed
},
source: {
user_agent: navigator.userAgent,
Expand Down
3 changes: 1 addition & 2 deletions acrobat/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const setLibs = (prodLibs, location) => {
if (branch === 'main' && hostname === 'www.stage.adobe.com') return 'https://www.stage.adobe.com/libs';
if (!(hostname.includes('.hlx.') || hostname.includes('local') || hostname.includes('stage'))) return prodLibs;
if (branch === 'local') return 'http://localhost:6456/libs';
const tld = hostname.includes('live') ? 'live' : 'page';
return branch.includes('--') ? `https://${branch}.hlx.${tld}/libs` : `https://${branch}--milo--adobecom.hlx.${tld}/libs`;
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
};

const getLocale = (locales, pathname = window.location.pathname) => {
Expand Down

0 comments on commit 1b479f1

Please sign in to comment.