Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gu imageworks extension
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
joetsuihk
gu imageworks extension
Commits
627ab87f
Commit
627ab87f
authored
Feb 22, 2022
by
edwin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor createDOMString, change fetch url and update filter logic again
parent
2a517d0e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
37 deletions
+21
-37
fetch.js
fetch/fetch.js
+21
-37
No files found.
fetch/fetch.js
View file @
627ab87f
...
...
@@ -2,7 +2,7 @@
const
baseurl
=
"https://digitallibrary-external.fastretailing.com/"
;
const
fetchNumber
=
30
;
const
sleepTime
=
30
00
;
const
sleepTime
=
25
00
;
let
allowDebugMessage
=
true
;
// adding the lightbox (control panel) to the body
...
...
@@ -93,7 +93,7 @@
// fetch product URL
let
currentms
=
new
Date
().
getTime
();
let
assetlist
=
await
fetchSKU
(
`
${
baseurl
}
api/asset?time=
${
currentms
}
&t=main_product%2FGU%2F
${
SKU
}
&t=datacategory%2Fecasset&r=north&z=
${
fetchNumber
}
&
et=hk&
c=DEFAULT`
,
`
${
SKU
}
product image`
);
let
assetlist
=
await
fetchSKU
(
`
${
baseurl
}
api/asset?time=
${
currentms
}
&t=main_product%2FGU%2F
${
SKU
}
&t=datacategory%2Fecasset&r=north&z=
${
fetchNumber
}
&c=DEFAULT`
,
`
${
SKU
}
product image`
);
let
DOMString
=
createDOMString
(
SKU
,
assetlist
);
container
.
insertAdjacentHTML
(
'beforeend'
,
DOMString
);
clientSideFilter
();
...
...
@@ -140,33 +140,10 @@
}
function
createDOMString
(
SKU
,
assetlist
){
return
assetlist
.
map
(
asset
=>
{
// determine whether it is product file
let
classes
=
""
;
let
tagid
=
asset
.
tags
.
map
(
x
=>
x
.
id
);
if
(
!
(
asset
.
file_extension
===
"jpg"
||
asset
.
file_extension
===
"gif"
)
||
asset
.
filename
.
includes
(
`
${
SKU
}
_I0`
)
||
(
asset
.
filename
.
includes
(
"goods_"
)
&&
!
asset
.
filename
.
includes
(
SKU
))
||
tagid
.
includes
(
"assettype/Poster"
)
||
asset
.
filename
.
includes
(
"GU_"
)
)
{
classes
=
"is-unrelated"
;
}
else
if
(
asset
.
filename
.
includes
(
`goods_
${
SKU
}
_sub`
)
||
asset
.
filename
.
includes
(
`_
${
SKU
}
_chip`
)
||
(
asset
.
filename
.
match
(
new
RegExp
(
`goods_[0-9]{2}_
${
SKU
}
$`
))
&&
asset
.
models
.
length
===
0
&&
asset
.
products
.
length
===
1
)
)
{
classes
=
"is-product"
;
}
else
if
(
tagid
.
find
(
x
=>
x
.
includes
(
"Model"
)
||
x
.
includes
(
"Appeal POP"
))
)
{
classes
=
"is-model"
;
}
else
{
classes
=
"is-unrelated"
;
}
let
multilist
=
filtering
(
assetlist
,
SKU
);
let
createString
=
(
asset
,
SKU
,
classes
)
=>
{
return
`
<div class="asset-item
${
classes
}
">
<div><img src="/api/asset/
${
asset
.
id
}
/thumbnail/medium?r=1" loading="lazy"/></div>
...
...
@@ -179,7 +156,13 @@
<span class="asset-date" hidden>
${
asset
.
updatedDate
}
</span>
</div>
`
;
}).
join
(
''
);
};
let
productString
=
multilist
[
"product"
].
map
(
x
=>
createString
(
x
,
SKU
,
"is-product"
)).
join
(
""
);
let
modelString
=
multilist
[
"model"
].
map
(
x
=>
createString
(
x
,
SKU
,
"is-model"
)).
join
(
""
);
let
unrelatedString
=
multilist
[
"unrelated"
].
map
(
x
=>
createString
(
x
,
SKU
,
"is-unrelated"
)).
join
(
""
);
return
productString
+
modelString
+
unrelatedString
;
}
// perform operation similar to old extension
...
...
@@ -200,7 +183,7 @@
// first link
let
currentms
=
new
Date
().
getTime
();
let
assetlist
=
await
fetchSKU
(
`
${
baseurl
}
api/asset?time=
${
currentms
}
&t=main_product%2FGU%2F
${
SKU
}
&t=datacategory%2Fecasset&r=north&z=
${
fetchNumber
}
&
et=hk&
c=DEFAULT`
,
`
${
SKU
}
product image`
);
let
assetlist
=
await
fetchSKU
(
`
${
baseurl
}
api/asset?time=
${
currentms
}
&t=main_product%2FGU%2F
${
SKU
}
&t=datacategory%2Fecasset&r=north&z=
${
fetchNumber
}
&c=DEFAULT`
,
`
${
SKU
}
product image`
);
let
downloadlist
=
filtering
(
assetlist
,
SKU
);
await
downloadList
(
downloadlist
[
"product"
],
`
${
SKU
}
`
);
await
sleep
(
sleepTime
);
...
...
@@ -294,7 +277,6 @@
}
// filter asset to different array
// only used on Download All SKUs
// usage:
// let downloadlist = filtering(assetlist, SKU);
...
...
@@ -305,26 +287,28 @@
let
tagid
=
item
.
tags
.
map
(
x
=>
x
.
id
);
if
(
item
.
filename
.
includes
(
`goods_
${
SKU
}
_sub`
)
||
item
.
filename
.
includes
(
`_
${
SKU
}
_chip`
)
||
(
item
.
filename
.
match
(
new
RegExp
(
`goods_[0-9]{2}_
${
SKU
}
$`
))
&&
item
.
models
.
length
===
0
&&
item
.
products
.
length
===
1
)
// file name include SKU and no model
if
(
item
.
filename
.
match
(
new
RegExp
(
`^goods_
${
SKU
}
_sub`
))
||
item
.
filename
.
includes
(
`_
${
SKU
}
_chip`
)
||
(
item
.
filename
.
match
(
new
RegExp
(
`
^
goods_[0-9]{2}_
${
SKU
}
$`
))
&&
item
.
models
.
length
===
0
&&
item
.
products
.
length
===
1
)
// file name include SKU and no model
)
{
arrlist
[
"product"
].
push
(
item
);
}
else
if
(
item
.
filename
.
includes
(
`
${
SKU
}
_I0`
)
||
(
item
.
filename
.
includes
(
"goods"
)
&&
!
item
.
filename
.
includes
(
SKU
))
||
(
item
.
filename
.
includes
(
"goods"
)
&&
(
!
item
.
filename
.
includes
(
SKU
)
||
item
.
filename
[
0
]
!==
'h'
))
||
tagid
.
includes
(
"assettype/Poster"
)
||
item
.
filename
.
includes
(
"GU_"
)
||
item
.
filename
.
match
(
new
RegExp
(
`^[0-9]{6}_.{8}_[0-9]{2}_.{4}`
))
)
{
// not adding to model
arrlist
[
"unrelated"
].
push
(
item
);
}
else
if
(
tagid
.
find
(
x
=>
x
.
includes
(
"Model"
)
||
x
.
includes
(
"Appeal POP"
))
)
{
arrlist
[
"model"
].
push
(
item
);
}
else
{
arrlist
[
"unrelated"
].
push
(
item
);
}
return
arrlist
;
},
{
"product"
:
[],
"model"
:
[]
});
// initial value
},
{
"product"
:
[],
"model"
:
[]
,
"unrelated"
:
[]
});
// initial value
return
multilist
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment