@@ -51,7 +51,7 @@ export async function createTask({ origin, clientid, token, task, service }) {
5151 const opts = getOpts ( clientid , token , JSON . stringify ( body ) , 'application/json' , 'POST' ) ;
5252
5353 try {
54- const resp = await fetch ( `${ origin } /api/l10n/v1.1 /tasks/${ workflow } /create` , opts ) ;
54+ const resp = await fetch ( `${ origin } /api/l10n/v1.2 /tasks/${ workflow } /create` , opts ) ;
5555 if ( ! resp . ok ) throw new Error ( resp . status ) ;
5656 return task ;
5757 } catch ( e ) {
@@ -62,19 +62,21 @@ export async function createTask({ origin, clientid, token, task, service }) {
6262export async function getTask ( { origin, clientid, token, workflow, name } ) {
6363 const opts = getOpts ( clientid , token ) ;
6464 try {
65- const resp = await fetch ( `${ origin } /api/l10n/v1.1 /tasks/${ workflow } /${ name } ` , opts ) ;
65+ const resp = await fetch ( `${ origin } /api/l10n/v1.2 /tasks/${ workflow } /${ name } ` , opts ) ;
6666 const json = await resp . json ( ) ;
6767 return { status : resp . status , json } ;
6868 } catch {
6969 return { error : 'Error getting task.' } ;
7070 }
7171}
7272
73+ // Helper function to ensure GLaaS compatibility with json extensions are converted to html
74+ export const getGlaasFilename = ( daBasePath ) => ( daBasePath . endsWith ( '.html' ) ? daBasePath : `${ daBasePath } .html` ) ;
75+
7376export async function addAssets ( {
7477 origin,
7578 clientid,
7679 token,
77- langs,
7880 task,
7981 items,
8082} , actions ) {
@@ -93,16 +95,20 @@ export async function addAssets({
9395 const body = new FormData ( ) ;
9496
9597 const file = new Blob ( [ item . content ] , { type : 'text/html' } ) ;
96- const details = {
97- assetName : item . daBasePath ,
98+ const glaasFilename = getGlaasFilename ( item . daBasePath ) ;
99+ const fileDetails = {
100+ assetName : glaasFilename ,
101+ assetType : 'SOURCE' ,
102+ targetLocales,
98103 metadata : { 'source-preview-url' : item . aemHref } ,
99104 } ;
100105
101- body . append ( 'file1' , file , item . daBasePath ) ;
102- body . append ( 'asset1 ' , new Blob ( [ JSON . stringify ( details ) ] , { type : 'application/json; charset=utf-8' } ) , '_asset_metadata_' ) ;
106+ // GLaaS v1.2
107+ body . append ( 'file ' , file , glaasFilename ) ;
103108
104109 const opts = getOpts ( clientid , token , body , null , 'POST' ) ;
105- const url = `${ origin } /api/l10n/v1.1/tasks/${ workflow } /${ name } /assets?targetLanguages=${ targetLocales . join ( ',' ) } ` ;
110+ // Add fileDetails parameter for GLaaS v1.2
111+ const url = `${ origin } /api/l10n/v1.2/tasks/${ workflow } /${ name } /assets?targetLanguages=${ targetLocales . join ( ',' ) } &fileDetails=${ encodeURIComponent ( JSON . stringify ( fileDetails ) ) } ` ;
106112
107113 try {
108114 const resp = await fetch ( url , opts ) ;
@@ -114,7 +120,7 @@ export async function addAssets({
114120 } ) ) ;
115121 task . sent += results . filter ( ( result ) => ( result . status ) ) . length ;
116122 task . error += results . filter ( ( result ) => ( result . error ) ) . length ;
117- updateLangTask ( task , langs ) ;
123+ updateLangTask ( task , task . langs ) ;
118124 }
119125 if ( task . error === 0 ) task . status = 'uploaded' ;
120126}
@@ -130,7 +136,7 @@ export async function updateStatus(service, token, task, newStatus = 'CREATED')
130136 const opts = getOpts ( clientid , token , body , null , 'POST' ) ;
131137
132138 const results = await Promise . all ( targetLocales . map ( async ( code ) => {
133- const url = `${ origin } /api/l10n/v1.1 /tasks/${ workflow } /${ name } /${ code } /updateStatus` ;
139+ const url = `${ origin } /api/l10n/v1.2 /tasks/${ workflow } /${ name } /${ code } /updateStatus` ;
134140 try {
135141 const resp = await fetch ( url , opts ) ;
136142 if ( ! resp . ok ) throw new Error ( resp . status ) ;
@@ -149,7 +155,7 @@ export async function downloadAsset(service, token, task, path) {
149155 const { origin, clientid } = service ;
150156 const { name, workflow, code } = task ;
151157 const opts = getOpts ( clientid , token , null , null , 'GET' ) ;
152- const url = `${ origin } /api/l10n/v1.1 /tasks/${ workflow } /${ name } /assets/${ code } ${ path } ` ;
158+ const url = `${ origin } /api/l10n/v1.2 /tasks/${ workflow } /${ name } /assets/${ code } ${ path } ` ;
153159 try {
154160 const resp = await fetch ( url , opts ) ;
155161 return resp . text ( ) ;
@@ -169,6 +175,7 @@ export async function prepareTargetPreview(task, urls, service) {
169175 project : workflowSplit [ 1 ] ,
170176 workflowName,
171177 taskName : name ,
178+ useTaskVersion : 'v2' ,
172179 targetLocales,
173180 urls : urls . map ( ( a ) => a . aemHref ) ,
174181 } ;
0 commit comments