Skip to content

Commit b28f478

Browse files
committed
fine tune
1 parent 635c0b8 commit b28f478

File tree

5 files changed

+20
-94
lines changed

5 files changed

+20
-94
lines changed

routers/web/repo/view_file.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,11 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
225225
return
226226
}
227227

228-
isRepresentableAsText := fInfo.st.IsRepresentableAsText()
229228
ctx.Data["IsLFSFile"] = fInfo.isLFSFile()
230229
ctx.Data["FileSize"] = fInfo.fileSize
231-
ctx.Data["IsRepresentableAsText"] = isRepresentableAsText
230+
ctx.Data["IsRepresentableAsText"] = fInfo.st.IsRepresentableAsText()
232231
ctx.Data["IsExecutable"] = entry.IsExecutable()
233-
ctx.Data["CanCopyContent"] = isRepresentableAsText
232+
ctx.Data["CanCopyContent"] = fInfo.st.IsRepresentableAsText() || fInfo.st.IsImage()
234233

235234
attrs, ok := prepareFileViewLfsAttrs(ctx)
236235
if !ok {

templates/repo/view_file.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</div>
6060
<a download class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.download_file"}}" href="{{$.RawFileLink}}">{{svg "octicon-download"}}</a>
6161
<a class="btn-octicon {{if not .CanCopyContent}}disabled{{end}}" data-global-click="onCopyContentButtonClick"
62-
{{if or .IsImageFile (and .IsRepresentableAsText (not .IsDisplayingSource))}}data-raw-link="{{$.RawFileLink}}"{{end}}
62+
{{if not .IsDisplayingSource}}data-raw-file-link="{{$.RawFileLink}}"{{end}}
6363
data-tooltip-content="{{if .CanCopyContent}}{{ctx.Locale.Tr "copy_content"}}{{else}}{{ctx.Locale.Tr "copy_type_unsupported"}}{{end}}"
6464
>{{svg "octicon-copy"}}</a>
6565
{{if .EnableFeed}}

web_src/js/features/copycontent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ const {i18n} = window.config;
99
export function initCopyContent() {
1010
registerGlobalEventFunc('click', 'onCopyContentButtonClick', async (btn: HTMLElement) => {
1111
if (btn.classList.contains('disabled') || btn.classList.contains('is-loading')) return;
12-
const rawLink = btn.getAttribute('data-raw-link');
12+
const rawFileLink = btn.getAttribute('data-raw-file-link');
1313

1414
let content, isRasterImage = false;
1515

1616
// when "data-raw-link" is present, we perform a fetch. this is either because
1717
// the text to copy is not in the DOM, or it is an image that should be
1818
// fetched to copy in full resolution
19-
if (rawLink) {
19+
if (rawFileLink) {
2020
btn.classList.add('is-loading', 'loading-icon-2px');
2121
try {
22-
const res = await GET(rawLink, {credentials: 'include', redirect: 'follow'});
22+
const res = await GET(rawFileLink, {credentials: 'include', redirect: 'follow'});
2323
const contentType = res.headers.get('content-type');
2424

2525
if (contentType.startsWith('image/') && !contentType.startsWith('image/svg')) {

web_src/js/render/plugins/3d-viewer-test-cube.stl

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

web_src/js/render/plugins/3d-viewer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ import type {FileRenderPlugin} from '../plugin.ts';
22
import {extname} from '../../utils.ts';
33

44
// support common 3D model file formats, use online-3d-viewer library for rendering
5+
6+
// eslint-disable-next-line multiline-comment-style
7+
/* a simple text STL file example:
8+
solid SimpleTriangle
9+
facet normal 0 0 1
10+
outer loop
11+
vertex 0 0 0
12+
vertex 1 0 0
13+
vertex 0 1 0
14+
endloop
15+
endfacet
16+
endsolid SimpleTriangle
17+
*/
18+
519
export function newRenderPlugin3DViewer(): FileRenderPlugin {
620
// Some extensions are text-based formats:
721
// .3mf .amf .brep: XML
@@ -28,7 +42,6 @@ export function newRenderPlugin3DViewer(): FileRenderPlugin {
2842

2943
async render(container: HTMLElement, fileUrl: string): Promise<void> {
3044
const OV = await import(/* webpackChunkName: "online-3d-viewer" */'online-3d-viewer');
31-
container.classList.add('model3d-content');
3245
const viewer = new OV.EmbeddedViewer(container, {
3346
backgroundColor: new OV.RGBAColor(59, 68, 76, 0),
3447
defaultColor: new OV.RGBColor(65, 131, 196),

0 commit comments

Comments
 (0)