Explorar o código

[upload] added folder upload

cgars %!s(int64=7) %!d(string=hai) anos
pai
achega
90e06dffed
Modificáronse 3 ficheiros con 105 adicións e 85 borrados
  1. 1 0
      models/repo_editor.go
  2. 99 84
      public/js/gogs.js
  3. 5 1
      routes/repo/editor.go

+ 1 - 0
models/repo_editor.go

@@ -523,6 +523,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
 	for _, upload := range uploads {
 	for _, upload := range uploads {
 		tmpPath := upload.LocalPath()
 		tmpPath := upload.LocalPath()
 		targetPath := path.Join(dirPath, upload.Name)
 		targetPath := path.Join(dirPath, upload.Name)
+		os.MkdirAll(filepath.Dir(targetPath), os.ModePerm)
 		repoFileName := path.Join(opts.TreePath, upload.Name)
 		repoFileName := path.Join(opts.TreePath, upload.Name)
 		if !com.IsFile(tmpPath) {
 		if !com.IsFile(tmpPath) {
 			continue
 			continue

+ 99 - 84
public/js/gogs.js

@@ -482,7 +482,7 @@ function initRepository() {
         $('#repo-clone-url').val($(this).data('link'));
         $('#repo-clone-url').val($(this).data('link'));
         $(this).addClass('blue');
         $(this).addClass('blue');
         $('#repo-clone-https').removeClass('blue');
         $('#repo-clone-https').removeClass('blue');
-		$('#repo-clone-gin').removeClass('blue');
+        $('#repo-clone-gin').removeClass('blue');
         localStorage.setItem('repo-clone-protocol', 'ssh');
         localStorage.setItem('repo-clone-protocol', 'ssh');
     });
     });
     $('#repo-clone-https').click(function () {
     $('#repo-clone-https').click(function () {
@@ -490,17 +490,17 @@ function initRepository() {
         $('#repo-clone-url').val($(this).data('link'));
         $('#repo-clone-url').val($(this).data('link'));
         $(this).addClass('blue');
         $(this).addClass('blue');
         $('#repo-clone-ssh').removeClass('blue');
         $('#repo-clone-ssh').removeClass('blue');
-		$('#repo-clone-gin').removeClass('blue');
+        $('#repo-clone-gin').removeClass('blue');
         localStorage.setItem('repo-clone-protocol', 'https');
         localStorage.setItem('repo-clone-protocol', 'https');
     });
     });
-	$('#repo-clone-gin').click(function () {
-		$('.clone-url').text($(this).data('link'));
-		$('#repo-clone-url').val($(this).data('link'));
-		$(this).addClass('blue');
-		$('#repo-clone-ssh').removeClass('blue');
-		$('#repo-clone-https').removeClass('blue');
-		localStorage.setItem('repo-clone-protocol', 'gin');
-	});
+    $('#repo-clone-gin').click(function () {
+        $('.clone-url').text($(this).data('link'));
+        $('#repo-clone-url').val($(this).data('link'));
+        $(this).addClass('blue');
+        $('#repo-clone-ssh').removeClass('blue');
+        $('#repo-clone-https').removeClass('blue');
+        localStorage.setItem('repo-clone-protocol', 'gin');
+    });
     $('#repo-clone-url').click(function () {
     $('#repo-clone-url').click(function () {
         $(this).select();
         $(this).select();
     });
     });
@@ -510,12 +510,13 @@ function initRepository() {
         initFilterSearchDropdown('.choose.branch .dropdown');
         initFilterSearchDropdown('.choose.branch .dropdown');
     }
     }
 
 
-	if ($('#download-repo-button')){
-			$('#download-repo-button').click(function () {
-				$('#download_modal')
-					.modal('show');
-			});
-		};
+    if ($('#download-repo-button')) {
+        $('#download-repo-button').click(function () {
+            $('#download_modal')
+                .modal('show');
+        });
+    }
+    ;
 }
 }
 
 
 function initWikiForm() {
 function initWikiForm() {
@@ -653,30 +654,30 @@ function setCodeMirror($editArea) {
         $editArea.val(cm.getValue());
         $editArea.val(cm.getValue());
     });
     });
 
 
-	codeMirrorEditor.on("keyup", function (cm, change) {
-		if (typeof (jsonEditor)!== 'undefined') {
-			try {
-				jsonEditor.set(JSON.parse(cm.getValue()));
-				document.getElementById("parseerr").innerHTML = "Valid JSON";
-				document.getElementById("parseerr").className="ui positive message"
-			}
-			catch(err) {
-				document.getElementById("parseerr").innerHTML = err.message;
-				document.getElementById("parseerr").className="ui negative message"
-			}
-		}
-		if (typeof (yamleditor)!== 'undefined') {
-			try {
-				yamleditor.set(YAML.parse(cm.getValue()));
-				document.getElementById("parseerr").innerHTML = "Valid YAML";
-				document.getElementById("parseerr").className="ui positive message"
-			}
-			catch(err) {
-				document.getElementById("parseerr").innerHTML = err.message;
-				document.getElementById("parseerr").className="ui negative message"
-			}
-		}
-	});
+    codeMirrorEditor.on("keyup", function (cm, change) {
+        if (typeof (jsonEditor) !== 'undefined') {
+            try {
+                jsonEditor.set(JSON.parse(cm.getValue()));
+                document.getElementById("parseerr").innerHTML = "Valid JSON";
+                document.getElementById("parseerr").className = "ui positive message"
+            }
+            catch (err) {
+                document.getElementById("parseerr").innerHTML = err.message;
+                document.getElementById("parseerr").className = "ui negative message"
+            }
+        }
+        if (typeof (yamleditor) !== 'undefined') {
+            try {
+                yamleditor.set(YAML.parse(cm.getValue()));
+                document.getElementById("parseerr").innerHTML = "Valid YAML";
+                document.getElementById("parseerr").className = "ui positive message"
+            }
+            catch (err) {
+                document.getElementById("parseerr").innerHTML = err.message;
+                document.getElementById("parseerr").className = "ui negative message"
+            }
+        }
+    });
 
 
     return true;
     return true;
 }
 }
@@ -1122,35 +1123,35 @@ function initCodeView() {
 }
 }
 
 
 function initCookieWarn() {
 function initCookieWarn() {
-	// Automatically shows on init if cookie isnt set
-	if (Cookies.get('cookieok') === undefined) {
-		$('.cookie.nag')
-			.nag({
-				key: 'accepts-cookies',
-				value: true
-			})
-		;
-		$('.nag.close').click(function () {
-			Cookies.set('cookieok', true,  { expires: 365 })
-		})
-
-	}
+    // Automatically shows on init if cookie isnt set
+    if (Cookies.get('cookieok') === undefined) {
+        $('.cookie.nag')
+            .nag({
+                key: 'accepts-cookies',
+                value: true
+            })
+        ;
+        $('.nag.close').click(function () {
+            Cookies.set('cookieok', true, {expires: 365})
+        })
+
+    }
 }
 }
 
 
 function initSuggest() {
 function initSuggest() {
-	$('.ui.ginsearch')
-		.search({
-			apiSettings: {
-				url: '/api/v1/repos/suggest/{query}'
-			},
-			fields: {
-				results: 'Items',
-				title: 'Title'
-			},
-			minCharacters: 3,
-			showNoResults: false
-		})
-	;
+    $('.ui.ginsearch')
+        .search({
+            apiSettings: {
+                url: '/api/v1/repos/suggest/{query}'
+            },
+            fields: {
+                results: 'Items',
+                title: 'Title'
+            },
+            minCharacters: 3,
+            showNoResults: false
+        })
+    ;
 }
 }
 
 
 function initUserSettings() {
 function initUserSettings() {
@@ -1222,7 +1223,7 @@ $(document).ready(function () {
     csrf = $('meta[name=_csrf]').attr("content");
     csrf = $('meta[name=_csrf]').attr("content");
     suburl = $('meta[name=_suburl]').attr("content");
     suburl = $('meta[name=_suburl]').attr("content");
 
 
-	// Set cursor to the end of autofocus input string
+    // Set cursor to the end of autofocus input string
     $('input[autofocus]').each(function () {
     $('input[autofocus]').each(function () {
         $(this).val($(this).val());
         $(this).val($(this).val());
     })
     })
@@ -1269,21 +1270,21 @@ $(document).ready(function () {
     });
     });
 
 
     // Highlight JS
     // Highlight JS
-	if (typeof hljs != 'undefined') {
-		if (typeof(Worker) !== "undefined") {
-			addEventListener('load', function () {
-				var code = document.querySelector('code');
-				var worker = new Worker('/plugins/highlighter.js');
-				worker.onmessage = function (event) {
-					code.innerHTML = event.data;
-				}
-				worker.postMessage(code.textContent);
-			})
-		} else {
-			hljs.initHighlightingOnLoad()
-		}
-
-	}
+    if (typeof hljs != 'undefined') {
+        if (typeof(Worker) !== "undefined") {
+            addEventListener('load', function () {
+                var code = document.querySelector('code');
+                var worker = new Worker('/plugins/highlighter.js');
+                worker.onmessage = function (event) {
+                    code.innerHTML = event.data;
+                }
+                worker.postMessage(code.textContent);
+            })
+        } else {
+            hljs.initHighlightingOnLoad()
+        }
+
+    }
 
 
     // Dropzone
     // Dropzone
     var $dropzone = $('#dropzone');
     var $dropzone = $('#dropzone');
@@ -1309,6 +1310,9 @@ $(document).ready(function () {
                     var input = $('<input id="' + data.uuid + '" name="files" type="hidden">').val(data.uuid);
                     var input = $('<input id="' + data.uuid + '" name="files" type="hidden">').val(data.uuid);
                     $('.files').append(input);
                     $('.files').append(input);
                 });
                 });
+                this.on("sending", function (file, xhr, formData) {
+                    formData.append("full_path", file.fullPath);
+                });
                 this.on("removedfile", function (file) {
                 this.on("removedfile", function (file) {
                     if (file.name in filenameDict) {
                     if (file.name in filenameDict) {
                         $('#' + filenameDict[file.name]).remove();
                         $('#' + filenameDict[file.name]).remove();
@@ -1320,6 +1324,17 @@ $(document).ready(function () {
                         });
                         });
                     }
                     }
                 })
                 })
+                this.on('addedfile', function (file) {
+
+                    var preview = document.getElementsByClassName('dz-filename');
+                    preview = preview[preview.length - 1];
+                    preview.removeChild(preview.firstChild);
+                    var imageName = document.createElement('span');
+                    imageName.innerHTML = file.fullPath;
+
+                    preview.insertBefore(imageName, preview.firstChild);
+
+                });
             }
             }
         });
         });
     }
     }
@@ -1467,8 +1482,8 @@ $(document).ready(function () {
     initOrganization();
     initOrganization();
     initAdmin();
     initAdmin();
     initCodeView();
     initCodeView();
-	initCookieWarn();
-	initSuggest();
+    initCookieWarn();
+    initSuggest();
 
 
     // Repo clone url.
     // Repo clone url.
     if ($('#repo-clone-url').length > 0) {
     if ($('#repo-clone-url').length > 0) {

+ 5 - 1
routes/repo/editor.go

@@ -22,6 +22,7 @@ import (
 	"github.com/G-Node/gogs/pkg/tool"
 	"github.com/G-Node/gogs/pkg/tool"
 	"github.com/G-Node/gogs/pkg/markup"
 	"github.com/G-Node/gogs/pkg/markup"
 	"github.com/G-Node/gogs/pkg/bindata"
 	"github.com/G-Node/gogs/pkg/bindata"
+	"path/filepath"
 )
 )
 
 
 const (
 const (
@@ -521,6 +522,9 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
 
 
 func UploadFileToServer(c *context.Context) {
 func UploadFileToServer(c *context.Context) {
 	file, header, err := c.Req.FormFile("file")
 	file, header, err := c.Req.FormFile("file")
+	fvalue := c.Req.Form
+	f_dir := filepath.Dir(fvalue.Get("full_path"))
+	log.Info("full_path:%s", f_dir)
 	if err != nil {
 	if err != nil {
 		c.Error(http.StatusInternalServerError, fmt.Sprintf("FormFile: %v", err))
 		c.Error(http.StatusInternalServerError, fmt.Sprintf("FormFile: %v", err))
 		return
 		return
@@ -550,7 +554,7 @@ func UploadFileToServer(c *context.Context) {
 		}
 		}
 	}
 	}
 
 
-	upload, err := models.NewUpload(header.Filename, buf, file)
+	upload, err := models.NewUpload(filepath.Join(f_dir, header.Filename), buf, file)
 	if err != nil {
 	if err != nil {
 		c.Error(http.StatusInternalServerError, fmt.Sprintf("NewUpload: %v", err))
 		c.Error(http.StatusInternalServerError, fmt.Sprintf("NewUpload: %v", err))
 		return
 		return