Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
ec90060d
Unverified
Commit
ec90060d
authored
1 year ago
by
Timothy Carambat
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Re-map some file mimes to support text (#842)
re-map some file mimes to support text
parent
60fc5f71
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
collector/utils/files/index.js
+6
-18
6 additions, 18 deletions
collector/utils/files/index.js
collector/utils/files/mime.js
+37
-0
37 additions, 0 deletions
collector/utils/files/mime.js
with
43 additions
and
18 deletions
collector/utils/files/index.js
+
6
−
18
View file @
ec90060d
const
fs
=
require
(
"
fs
"
);
const
path
=
require
(
"
path
"
);
const
{
getType
}
=
require
(
"
mime
"
);
const
{
MimeDetector
}
=
require
(
"
./
mime
"
);
function
isTextType
(
filepath
)
{
if
(
!
fs
.
existsSync
(
filepath
))
return
false
;
// These are types of mime primary classes that for sure
// cannot also for forced into a text type.
const
nonTextTypes
=
[
"
multipart
"
,
"
image
"
,
"
model
"
,
"
audio
"
,
"
video
"
];
// These are full-mimes we for sure cannot parse or interpret as text
// documents
const
BAD_MIMES
=
[
"
application/octet-stream
"
,
"
application/zip
"
,
"
application/pkcs8
"
,
"
application/vnd.microsoft.portable-executable
"
,
"
application/x-msdownload
"
,
];
try
{
const
mime
=
getType
(
filepath
);
if
(
BAD_MIMES
.
includes
(
mime
))
return
false
;
if
(
!
fs
.
existsSync
(
filepath
))
return
false
;
const
mimeLib
=
new
MimeDetector
();
const
mime
=
mimeLib
.
getType
(
filepath
);
if
(
mimeLib
.
badMimes
.
includes
(
mime
))
return
false
;
const
type
=
mime
.
split
(
"
/
"
)[
0
];
if
(
nonTextTypes
.
includes
(
type
))
return
false
;
if
(
mimeLib
.
nonTextTypes
.
includes
(
type
))
return
false
;
return
true
;
}
catch
{
return
false
;
...
...
This diff is collapsed.
Click to expand it.
collector/utils/files/mime.js
0 → 100644
+
37
−
0
View file @
ec90060d
const
MimeLib
=
require
(
"
mime
"
);
class
MimeDetector
{
nonTextTypes
=
[
"
multipart
"
,
"
image
"
,
"
model
"
,
"
audio
"
,
"
video
"
];
badMimes
=
[
"
application/octet-stream
"
,
"
application/zip
"
,
"
application/pkcs8
"
,
"
application/vnd.microsoft.portable-executable
"
,
"
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
"
,
// XLSX are binaries and need to be handled explicitly.
"
application/x-msdownload
"
,
];
constructor
()
{
this
.
lib
=
MimeLib
;
this
.
setOverrides
();
}
setOverrides
()
{
// the .ts extension maps to video/mp2t because of https://en.wikipedia.org/wiki/MPEG_transport_stream
// which has had this extension far before TS was invented. So need to force re-map this MIME map.
this
.
lib
.
define
(
{
"
text/plain
"
:
[
"
ts
"
,
"
py
"
,
"
opts
"
,
"
lock
"
,
"
jsonl
"
],
},
true
);
}
getType
(
filepath
)
{
return
this
.
lib
.
getType
(
filepath
);
}
}
module
.
exports
=
{
MimeDetector
,
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment