Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b707a7

Browse files
BrunoQuaresmapull[bot]
authored andcommitted
refactor(site): Remove untar dep and support nested folders on template version page (#6244)
1 parente993951 commit1b707a7

File tree

11 files changed

+95
-132
lines changed

11 files changed

+95
-132
lines changed

‎site/js-untar.d.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎site/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"history":"5.3.0",
6060
"i18next":"21.9.1",
6161
"jest-location-mock":"1.0.9",
62-
"js-untar":"2.0.0",
6362
"just-debounce-it":"3.1.1",
6463
"lodash":"4.17.21",
6564
"playwright":"^1.29.2",
@@ -103,7 +102,6 @@
103102
"@types/react-helmet":"6.1.5",
104103
"@types/react-syntax-highlighter":"15.5.5",
105104
"@types/semver":"7.3.12",
106-
"@types/tar-js":"^0.3.2",
107105
"@types/ua-parser-js":"0.7.36",
108106
"@types/uuid":"8.3.4",
109107
"@typescript-eslint/eslint-plugin":"5.50.0",

‎site/site.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ func cspHeaders(next http.Handler) http.Handler {
326326
// Report all violations back to the server to log
327327
CSPDirectiveReportURI: {"/api/v2/csp/reports"},
328328
CSPFrameAncestors: {"'none'"},
329-
// worker for loading the .tar files on FE using js-untar
330-
CSPDirectiveWorkerSrc: {"'self' blob:"},
331329

332330
// Only scripts can manipulate the dom. This prevents someone from
333331
// naming themselves something like '<svg onload="alert(/cross-site-scripting/)" />'.

‎site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const TemplateVersionEditorPage: FC = () => {
2727
},
2828
{
2929
onSuccess(data){
30-
sendEvent({type:"INITIALIZE",untarFiles:data.untarFiles})
30+
sendEvent({type:"INITIALIZE",tarReader:data.tarReader})
3131
},
3232
},
3333
)

‎site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/data.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import{useQuery,UseQueryOptions}from"@tanstack/react-query"
22
import{getFile,getTemplateByName,getTemplateVersionByName}from"api/api"
3+
import{TarReader}from"util/tar"
34
import{createTemplateVersionFileTree}from"util/templateVersion"
4-
importuntar,{FileasUntarFile}from"js-untar"
55

66
constgetTemplateVersionData=async(
77
orgId:string,
@@ -13,17 +13,15 @@ const getTemplateVersionData = async (
1313
getTemplateVersionByName(orgId,templateName,versionName),
1414
])
1515
consttarFile=awaitgetFile(version.job.file_id)
16-
letuntarFiles:UntarFile[]=[]
17-
awaituntar(tarFile).then((files)=>{
18-
untarFiles=files
19-
})
20-
constfileTree=awaitcreateTemplateVersionFileTree(untarFiles)
16+
consttarReader=newTarReader()
17+
awaittarReader.readFile(tarFile)
18+
constfileTree=awaitcreateTemplateVersionFileTree(tarReader)
2119

2220
return{
2321
template,
2422
version,
2523
fileTree,
26-
untarFiles,
24+
tarReader,
2725
}
2826
}
2927

‎site/src/util/tar.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ test("tar", async () => {
99
writer.addFile("b.txt",newBlob(["world"]),{ mtime})
1010
writer.addFile("c.txt","",{ mtime})
1111
writer.addFolder("etc",{ mtime})
12-
writer.addFile("etc/d.txt","",{ mtime})
12+
writer.addFile("etc/d.txt","Some text content",{
13+
mtime,
14+
user:"coder",
15+
group:"codergroup",
16+
mode:parseInt("777",8),
17+
})
1318
constblob=awaitwriter.write()
1419

1520
// Read
@@ -32,8 +37,11 @@ test("tar", async () => {
3237
})
3338
verifyFile(fileInfos[4],reader.getTextFile(fileInfos[4].name)asstring,{
3439
name:"etc/d.txt",
35-
content:"",
40+
content:"Some text content",
3641
})
42+
expect(fileInfos[4].group).toEqual("codergroup")
43+
expect(fileInfos[4].user).toEqual("coder")
44+
expect(fileInfos[4].mode).toEqual(parseInt("777",8))
3745
})
3846

3947
functionverifyFile(

‎site/src/util/tar.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export interface ITarFileInfo {
1313
name:string
1414
type:TarFileType
1515
size:number
16+
mode:number
17+
mtime:number
18+
user:string
19+
group:string
1620
headerOffset:number
1721
}
1822

@@ -34,7 +38,7 @@ export interface ITarWriteOptions {
3438
}
3539

3640
exportclassTarReader{
37-
privatefileInfo:ITarFileInfo[]=[]
41+
publicfileInfo:ITarFileInfo[]=[]
3842
private_buffer:ArrayBuffer|null=null
3943

4044
constructor(){
@@ -64,22 +68,28 @@ export class TarReader {
6468
privatereadFileInfo(){
6569
this.fileInfo=[]
6670
letoffset=0
67-
letfileSize=0
68-
letfileName=""
69-
letfileType:TarFileType
71+
7072
while(offset<this.buffer.byteLength-512){
71-
fileName=this.readFileName(offset)
73+
constfileName=this.readFileName(offset)
7274
if(!fileName){
7375
break
7476
}
75-
fileType=this.readFileType(offset)
76-
fileSize=this.readFileSize(offset)
77+
constfileType=this.readFileType(offset)
78+
constfileSize=this.readFileSize(offset)
79+
constfileMode=this.readFileMode(offset)
80+
constfileMtime=this.readFileMtime(offset)
81+
constfileUser=this.readFileUser(offset)
82+
constfileGroup=this.readFileGroup(offset)
7783

7884
this.fileInfo.push({
7985
name:fileName,
8086
type:fileType,
8187
size:fileSize,
8288
headerOffset:offset,
89+
mode:fileMode,
90+
mtime:fileMtime,
91+
user:fileUser,
92+
group:fileGroup,
8393
})
8494

8595
offset+=512+512*Math.floor((fileSize+511)/512)
@@ -100,6 +110,24 @@ export class TarReader {
100110
returnthis.readString(offset,100)
101111
}
102112

113+
privatereadFileMode(offset:number){
114+
constmode=this.readString(offset+100,8)
115+
returnparseInt(mode,8)
116+
}
117+
118+
privatereadFileMtime(offset:number){
119+
constmtime=this.readString(offset+136,12)
120+
returnparseInt(mtime,8)
121+
}
122+
123+
privatereadFileUser(offset:number){
124+
returnthis.readString(offset+265,32)
125+
}
126+
127+
privatereadFileGroup(offset:number){
128+
returnthis.readString(offset+297,32)
129+
}
130+
103131
privatereadFileType(offset:number){
104132
consttypeView=newUint8Array(this.buffer,offset+156,1)
105133
consttypeStr=String.fromCharCode(typeView[0])

‎site/src/util/templateVersion.ts

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asAPIfrom"api/api"
22
import{TemplateVersion}from"api/typesGenerated"
3-
importuntar,{FileasUntarFile}from"js-untar"
43
import{FileTree,setFile}from"./filetree"
4+
import{TarReader}from"./tar"
55

66
/**
77
* Content by filename
@@ -10,32 +10,16 @@ export type TemplateVersionFiles = Record<string, string>
1010

1111
exportconstgetTemplateVersionFiles=async(
1212
version:TemplateVersion,
13-
allowedExtensions:string[],
14-
allowedFiles:string[],
1513
):Promise<TemplateVersionFiles>=>{
1614
constfiles:TemplateVersionFiles={}
1715
consttarFile=awaitAPI.getFile(version.job.file_id)
18-
constblobs:Record<string,Blob>={}
19-
20-
awaituntar(tarFile).then(undefined,undefined,async(file)=>{
21-
constpaths=file.name.split("/")
22-
constfilename=paths[paths.length-1]
23-
const[_,extension]=filename.split(".")
24-
25-
if(
26-
allowedExtensions.includes(extension)||
27-
allowedFiles.includes(filename)
28-
){
29-
blobs[filename]=file.blob
16+
consttarReader=newTarReader()
17+
awaittarReader.readFile(tarFile)
18+
for(constfileoftarReader.fileInfo){
19+
if(isAllowedFile(file.name)){
20+
files[file.name]=tarReader.getTextFile(file.name)asstring
3021
}
31-
})
32-
33-
awaitPromise.all(
34-
Object.entries(blobs).map(async([filename,blob])=>{
35-
files[filename]=awaitblob.text()
36-
}),
37-
)
38-
22+
}
3923
returnfiles
4024
}
4125

@@ -46,23 +30,17 @@ export const isAllowedFile = (name: string) => {
4630
}
4731

4832
exportconstcreateTemplateVersionFileTree=async(
49-
untarFiles:UntarFile[],
33+
tarReader:TarReader,
5034
):Promise<FileTree>=>{
5135
letfileTree:FileTree={}
52-
constblobs:Record<string,Blob>={}
53-
54-
for(constuntarFileofuntarFiles){
55-
if(isAllowedFile(untarFile.name)){
56-
blobs[untarFile.name]=untarFile.blob
36+
for(constfileoftarReader.fileInfo){
37+
if(isAllowedFile(file.name)){
38+
fileTree=setFile(
39+
file.name,
40+
tarReader.getTextFile(file.name)asstring,
41+
fileTree,
42+
)
5743
}
5844
}
59-
60-
awaitPromise.all(
61-
Object.entries(blobs).map(async([fullPath,blob])=>{
62-
constcontent=awaitblob.text()
63-
fileTree=setFile(fullPath,content,fileTree)
64-
}),
65-
)
66-
6745
returnfileTree
6846
}

‎site/src/xServices/templateVersion/templateVersionXService.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,9 @@ export const templateVersionMachine = createMachine(
162162
}
163163
constloadFilesPromises:ReturnType<typeofgetTemplateVersionFiles>[]=
164164
[]
165-
constallowedExtensions=["tf","md"]
166-
constallowedFiles=["Dockerfile"]
167-
loadFilesPromises.push(
168-
getTemplateVersionFiles(
169-
currentVersion,
170-
allowedExtensions,
171-
allowedFiles,
172-
),
173-
)
165+
loadFilesPromises.push(getTemplateVersionFiles(currentVersion))
174166
if(previousVersion){
175-
loadFilesPromises.push(
176-
getTemplateVersionFiles(
177-
previousVersion,
178-
allowedExtensions,
179-
allowedFiles,
180-
),
181-
)
167+
loadFilesPromises.push(getTemplateVersionFiles(previousVersion))
182168
}
183169
const[currentFiles,previousFiles]=awaitPromise.all(
184170
loadFilesPromises,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp