editor.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "fmt"
  7. "io/ioutil"
  8. "net/http"
  9. "path"
  10. "path/filepath"
  11. "strings"
  12. log "gopkg.in/clog.v1"
  13. "github.com/G-Node/git-module"
  14. "github.com/G-Node/gogs/internal/bindata"
  15. "github.com/G-Node/gogs/internal/context"
  16. "github.com/G-Node/gogs/internal/db"
  17. "github.com/G-Node/gogs/internal/db/errors"
  18. "github.com/G-Node/gogs/internal/form"
  19. "github.com/G-Node/gogs/internal/markup"
  20. "github.com/G-Node/gogs/internal/setting"
  21. "github.com/G-Node/gogs/internal/template"
  22. "github.com/G-Node/gogs/internal/tool"
  23. )
  24. const (
  25. EDIT_FILE = "repo/editor/edit"
  26. EDIT_DIFF_PREVIEW = "repo/editor/diff_preview"
  27. DELETE_FILE = "repo/editor/delete"
  28. UPLOAD_FILE = "repo/editor/upload"
  29. )
  30. // getParentTreeFields returns list of parent tree names and corresponding tree paths
  31. // based on given tree path.
  32. func getParentTreeFields(treePath string) (treeNames []string, treePaths []string) {
  33. if len(treePath) == 0 {
  34. return treeNames, treePaths
  35. }
  36. treeNames = strings.Split(treePath, "/")
  37. treePaths = make([]string, len(treeNames))
  38. for i := range treeNames {
  39. treePaths[i] = strings.Join(treeNames[:i+1], "/")
  40. }
  41. return treeNames, treePaths
  42. }
  43. func editFile(c *context.Context, isNewFile bool) {
  44. c.PageIs("Edit")
  45. c.RequireHighlightJS()
  46. c.RequireSimpleMDE()
  47. c.Data["IsNewFile"] = isNewFile
  48. treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
  49. if !isNewFile {
  50. entry, err := c.Repo.Commit.GetTreeEntryByPath(c.Repo.TreePath)
  51. if err != nil {
  52. c.NotFoundOrServerError("GetTreeEntryByPath", git.IsErrNotExist, err)
  53. return
  54. }
  55. // No way to edit a directory online.
  56. if entry.IsDir() {
  57. c.NotFound()
  58. return
  59. }
  60. blob := entry.Blob()
  61. dataRc, err := blob.Data()
  62. if err != nil {
  63. c.ServerError("blob.Data", err)
  64. return
  65. }
  66. c.Data["FileSize"] = blob.Size()
  67. c.Data["FileName"] = blob.Name()
  68. c.Data["IsJSON"] = markup.IsJSON(blob.Name())
  69. c.Data["IsYAML"] = markup.IsYAML(blob.Name())
  70. buf := make([]byte, 1024)
  71. n, _ := dataRc.Read(buf)
  72. buf = buf[:n]
  73. // Only text file are editable online.
  74. if !tool.IsTextFile(buf) {
  75. c.NotFound()
  76. return
  77. }
  78. c.Data["IsODML"] = tool.IsODMLFile(buf)
  79. d, _ := ioutil.ReadAll(dataRc)
  80. buf = append(buf, d...)
  81. if err, content := template.ToUTF8WithErr(buf); err != nil {
  82. if err != nil {
  83. log.Error(2, "Failed to convert encoding to UTF-8: %v", err)
  84. }
  85. c.Data["FileContent"] = string(buf)
  86. } else {
  87. c.Data["FileContent"] = content
  88. }
  89. } else {
  90. treeNames = append(treeNames, "") // Append empty string to allow user name the new file.
  91. }
  92. c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
  93. c.Data["TreeNames"] = treeNames
  94. c.Data["TreePaths"] = treePaths
  95. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  96. c.Data["commit_summary"] = ""
  97. c.Data["commit_message"] = ""
  98. c.Data["commit_choice"] = "direct"
  99. c.Data["new_branch_name"] = ""
  100. c.Data["last_commit"] = c.Repo.Commit.ID
  101. c.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
  102. c.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
  103. c.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
  104. c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", setting.AppSubURL, c.Repo.Repository.FullName())
  105. c.Success(EDIT_FILE)
  106. }
  107. func EditFile(c *context.Context) {
  108. editFile(c, false)
  109. }
  110. func NewFile(c *context.Context) {
  111. editFile(c, true)
  112. }
  113. func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
  114. c.PageIs("Edit")
  115. c.RequireHighlightJS()
  116. c.RequireSimpleMDE()
  117. c.Data["IsNewFile"] = isNewFile
  118. oldBranchName := c.Repo.BranchName
  119. branchName := oldBranchName
  120. oldTreePath := c.Repo.TreePath
  121. lastCommit := f.LastCommit
  122. f.LastCommit = c.Repo.Commit.ID.String()
  123. if f.IsNewBrnach() {
  124. branchName = f.NewBranchName
  125. }
  126. f.TreePath = strings.Trim(path.Clean("/"+f.TreePath), " /")
  127. treeNames, treePaths := getParentTreeFields(f.TreePath)
  128. c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
  129. c.Data["TreePath"] = f.TreePath
  130. c.Data["TreeNames"] = treeNames
  131. c.Data["TreePaths"] = treePaths
  132. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + branchName
  133. c.Data["FileContent"] = f.Content
  134. c.Data["commit_summary"] = f.CommitSummary
  135. c.Data["commit_message"] = f.CommitMessage
  136. c.Data["commit_choice"] = f.CommitChoice
  137. c.Data["new_branch_name"] = branchName
  138. c.Data["last_commit"] = f.LastCommit
  139. c.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
  140. c.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
  141. c.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
  142. if c.HasError() {
  143. c.Success(EDIT_FILE)
  144. return
  145. }
  146. if len(f.TreePath) == 0 {
  147. c.FormErr("TreePath")
  148. c.RenderWithErr(c.Tr("repo.editor.filename_cannot_be_empty"), EDIT_FILE, &f)
  149. return
  150. }
  151. if oldBranchName != branchName {
  152. if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
  153. c.FormErr("NewBranchName")
  154. c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), EDIT_FILE, &f)
  155. return
  156. }
  157. }
  158. var newTreePath string
  159. for index, part := range treeNames {
  160. newTreePath = path.Join(newTreePath, part)
  161. entry, err := c.Repo.Commit.GetTreeEntryByPath(newTreePath)
  162. if err != nil {
  163. if git.IsErrNotExist(err) {
  164. // Means there is no item with that name, so we're good
  165. break
  166. }
  167. c.ServerError("Repo.Commit.GetTreeEntryByPath", err)
  168. return
  169. }
  170. if index != len(treeNames)-1 {
  171. if !entry.IsDir() {
  172. c.FormErr("TreePath")
  173. c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), EDIT_FILE, &f)
  174. return
  175. }
  176. } else {
  177. if entry.IsLink() {
  178. c.FormErr("TreePath")
  179. c.RenderWithErr(c.Tr("repo.editor.file_is_a_symlink", part), EDIT_FILE, &f)
  180. return
  181. } else if entry.IsDir() {
  182. c.FormErr("TreePath")
  183. c.RenderWithErr(c.Tr("repo.editor.filename_is_a_directory", part), EDIT_FILE, &f)
  184. return
  185. }
  186. }
  187. }
  188. if !isNewFile {
  189. _, err := c.Repo.Commit.GetTreeEntryByPath(oldTreePath)
  190. if err != nil {
  191. if git.IsErrNotExist(err) {
  192. c.FormErr("TreePath")
  193. c.RenderWithErr(c.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), EDIT_FILE, &f)
  194. } else {
  195. c.ServerError("GetTreeEntryByPath", err)
  196. }
  197. return
  198. }
  199. if lastCommit != c.Repo.CommitID {
  200. files, err := c.Repo.Commit.GetFilesChangedSinceCommit(lastCommit)
  201. if err != nil {
  202. c.ServerError("GetFilesChangedSinceCommit", err)
  203. return
  204. }
  205. for _, file := range files {
  206. if file == f.TreePath {
  207. c.RenderWithErr(c.Tr("repo.editor.file_changed_while_editing", c.Repo.RepoLink+"/compare/"+lastCommit+"..."+c.Repo.CommitID), EDIT_FILE, &f)
  208. return
  209. }
  210. }
  211. }
  212. }
  213. if oldTreePath != f.TreePath {
  214. // We have a new filename (rename or completely new file) so we need to make sure it doesn't already exist, can't clobber.
  215. entry, err := c.Repo.Commit.GetTreeEntryByPath(f.TreePath)
  216. if err != nil {
  217. if !git.IsErrNotExist(err) {
  218. c.ServerError("GetTreeEntryByPath", err)
  219. return
  220. }
  221. }
  222. if entry != nil {
  223. c.FormErr("TreePath")
  224. c.RenderWithErr(c.Tr("repo.editor.file_already_exists", f.TreePath), EDIT_FILE, &f)
  225. return
  226. }
  227. }
  228. message := strings.TrimSpace(f.CommitSummary)
  229. if len(message) == 0 {
  230. if isNewFile {
  231. message = c.Tr("repo.editor.add", f.TreePath)
  232. } else {
  233. message = c.Tr("repo.editor.update", f.TreePath)
  234. }
  235. }
  236. f.CommitMessage = strings.TrimSpace(f.CommitMessage)
  237. if len(f.CommitMessage) > 0 {
  238. message += "\n\n" + f.CommitMessage
  239. }
  240. if err := c.Repo.Repository.UpdateRepoFile(c.User, db.UpdateRepoFileOptions{
  241. LastCommitID: lastCommit,
  242. OldBranch: oldBranchName,
  243. NewBranch: branchName,
  244. OldTreeName: oldTreePath,
  245. NewTreeName: f.TreePath,
  246. Message: message,
  247. Content: strings.Replace(f.Content, "\r", "", -1),
  248. IsNewFile: isNewFile,
  249. }); err != nil {
  250. log.Error(2, "Failed to update repo file: %v", err)
  251. c.FormErr("TreePath")
  252. c.RenderWithErr(c.Tr("repo.editor.fail_to_update_file", f.TreePath, errors.InternalServerError), EDIT_FILE, &f)
  253. return
  254. }
  255. if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
  256. c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
  257. } else {
  258. c.Redirect(c.Repo.RepoLink + "/src/" + branchName + "/" + f.TreePath)
  259. }
  260. }
  261. func EditFilePost(c *context.Context, f form.EditRepoFile) {
  262. editFilePost(c, f, false)
  263. }
  264. func NewFilePost(c *context.Context, f form.EditRepoFile) {
  265. editFilePost(c, f, true)
  266. }
  267. func DiffPreviewPost(c *context.Context, f form.EditPreviewDiff) {
  268. treePath := c.Repo.TreePath
  269. entry, err := c.Repo.Commit.GetTreeEntryByPath(treePath)
  270. if err != nil {
  271. c.Error(500, "GetTreeEntryByPath: "+err.Error())
  272. return
  273. } else if entry.IsDir() {
  274. c.Error(422)
  275. return
  276. }
  277. diff, err := c.Repo.Repository.GetDiffPreview(c.Repo.BranchName, treePath, f.Content)
  278. if err != nil {
  279. c.Error(500, "GetDiffPreview: "+err.Error())
  280. return
  281. }
  282. if diff.NumFiles() == 0 {
  283. c.PlainText(200, []byte(c.Tr("repo.editor.no_changes_to_show")))
  284. return
  285. }
  286. c.Data["File"] = diff.Files[0]
  287. c.HTML(200, EDIT_DIFF_PREVIEW)
  288. }
  289. func DeleteFile(c *context.Context) {
  290. c.PageIs("Delete")
  291. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  292. c.Data["TreePath"] = c.Repo.TreePath
  293. c.Data["commit_summary"] = ""
  294. c.Data["commit_message"] = ""
  295. c.Data["commit_choice"] = "direct"
  296. c.Data["new_branch_name"] = ""
  297. c.Success(DELETE_FILE)
  298. }
  299. func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
  300. c.PageIs("Delete")
  301. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  302. c.Data["TreePath"] = c.Repo.TreePath
  303. oldBranchName := c.Repo.BranchName
  304. branchName := oldBranchName
  305. if f.IsNewBrnach() {
  306. branchName = f.NewBranchName
  307. }
  308. c.Data["commit_summary"] = f.CommitSummary
  309. c.Data["commit_message"] = f.CommitMessage
  310. c.Data["commit_choice"] = f.CommitChoice
  311. c.Data["new_branch_name"] = branchName
  312. if c.HasError() {
  313. c.Success(DELETE_FILE)
  314. return
  315. }
  316. if oldBranchName != branchName {
  317. if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
  318. c.FormErr("NewBranchName")
  319. c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), DELETE_FILE, &f)
  320. return
  321. }
  322. }
  323. message := strings.TrimSpace(f.CommitSummary)
  324. if len(message) == 0 {
  325. message = c.Tr("repo.editor.delete", c.Repo.TreePath)
  326. }
  327. f.CommitMessage = strings.TrimSpace(f.CommitMessage)
  328. if len(f.CommitMessage) > 0 {
  329. message += "\n\n" + f.CommitMessage
  330. }
  331. if err := c.Repo.Repository.DeleteRepoFile(c.User, db.DeleteRepoFileOptions{
  332. LastCommitID: c.Repo.CommitID,
  333. OldBranch: oldBranchName,
  334. NewBranch: branchName,
  335. TreePath: c.Repo.TreePath,
  336. Message: message,
  337. }); err != nil {
  338. log.Error(2, "Failed to delete repo file: %v", err)
  339. c.RenderWithErr(c.Tr("repo.editor.fail_to_delete_file", c.Repo.TreePath, errors.InternalServerError), DELETE_FILE, &f)
  340. return
  341. }
  342. if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
  343. c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
  344. } else {
  345. c.Flash.Success(c.Tr("repo.editor.file_delete_success", c.Repo.TreePath))
  346. c.Redirect(c.Repo.RepoLink + "/src/" + branchName)
  347. }
  348. }
  349. func renderUploadSettings(c *context.Context) {
  350. c.RequireDropzone()
  351. c.Data["UploadAllowedTypes"] = strings.Join(setting.Repository.Upload.AllowedTypes, ",")
  352. c.Data["UploadMaxSize"] = setting.Repository.Upload.FileMaxSize
  353. c.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles
  354. }
  355. func UploadFile(c *context.Context) {
  356. c.PageIs("Upload")
  357. renderUploadSettings(c)
  358. treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
  359. if len(treeNames) == 0 {
  360. // We must at least have one element for user to input.
  361. treeNames = []string{""}
  362. }
  363. c.Data["TreeNames"] = treeNames
  364. c.Data["TreePaths"] = treePaths
  365. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  366. c.Data["commit_summary"] = ""
  367. c.Data["commit_message"] = ""
  368. c.Data["commit_choice"] = "direct"
  369. c.Data["new_branch_name"] = ""
  370. c.Success(UPLOAD_FILE)
  371. }
  372. func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
  373. c.PageIs("Upload")
  374. renderUploadSettings(c)
  375. oldBranchName := c.Repo.BranchName
  376. branchName := oldBranchName
  377. if f.IsNewBrnach() {
  378. branchName = f.NewBranchName
  379. }
  380. f.TreePath = strings.Trim(path.Clean("/"+f.TreePath), " /")
  381. treeNames, treePaths := getParentTreeFields(f.TreePath)
  382. if len(treeNames) == 0 {
  383. // We must at least have one element for user to input.
  384. treeNames = []string{""}
  385. }
  386. c.Data["TreePath"] = f.TreePath
  387. c.Data["TreeNames"] = treeNames
  388. c.Data["TreePaths"] = treePaths
  389. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + branchName
  390. c.Data["commit_summary"] = f.CommitSummary
  391. c.Data["commit_message"] = f.CommitMessage
  392. c.Data["commit_choice"] = f.CommitChoice
  393. c.Data["new_branch_name"] = branchName
  394. if c.HasError() {
  395. c.Success(UPLOAD_FILE)
  396. return
  397. }
  398. if oldBranchName != branchName {
  399. if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
  400. c.FormErr("NewBranchName")
  401. c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), UPLOAD_FILE, &f)
  402. return
  403. }
  404. }
  405. var newTreePath string
  406. for _, part := range treeNames {
  407. newTreePath = path.Join(newTreePath, part)
  408. entry, err := c.Repo.Commit.GetTreeEntryByPath(newTreePath)
  409. if err != nil {
  410. if git.IsErrNotExist(err) {
  411. // Means there is no item with that name, so we're good
  412. break
  413. }
  414. c.ServerError("GetTreeEntryByPath", err)
  415. return
  416. }
  417. // User can only upload files to a directory.
  418. if !entry.IsDir() {
  419. c.FormErr("TreePath")
  420. c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), UPLOAD_FILE, &f)
  421. return
  422. }
  423. }
  424. message := strings.TrimSpace(f.CommitSummary)
  425. if len(message) == 0 {
  426. message = c.Tr("repo.editor.upload_files_to_dir", f.TreePath)
  427. }
  428. f.CommitMessage = strings.TrimSpace(f.CommitMessage)
  429. if len(f.CommitMessage) > 0 {
  430. message += "\n\n" + f.CommitMessage
  431. }
  432. if err := c.Repo.Repository.UploadRepoFiles(c.User, db.UploadRepoFileOptions{
  433. LastCommitID: c.Repo.CommitID,
  434. OldBranch: oldBranchName,
  435. NewBranch: branchName,
  436. TreePath: f.TreePath,
  437. Message: message,
  438. Files: f.Files,
  439. }); err != nil {
  440. log.Error(2, "Failed to upload files: %v", err)
  441. c.FormErr("TreePath")
  442. c.RenderWithErr(c.Tr("repo.editor.unable_to_upload_files", f.TreePath, errors.InternalServerError), UPLOAD_FILE, &f)
  443. return
  444. }
  445. if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
  446. c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
  447. } else {
  448. c.Redirect(c.Repo.RepoLink + "/src/" + branchName + "/" + f.TreePath)
  449. }
  450. }
  451. func UploadFileToServer(c *context.Context) {
  452. file, header, err := c.Req.FormFile("file")
  453. fvalue := c.Req.Form
  454. fp := filepath.Dir(fvalue.Get("full_path"))
  455. log.Info("full_path: %s", fp)
  456. if err != nil {
  457. c.Error(http.StatusInternalServerError, fmt.Sprintf("FormFile: %v", err))
  458. return
  459. }
  460. defer file.Close()
  461. buf := make([]byte, 1024)
  462. n, _ := file.Read(buf)
  463. if n > 0 {
  464. buf = buf[:n]
  465. }
  466. fileType := http.DetectContentType(buf)
  467. if len(setting.Repository.Upload.AllowedTypes) > 0 {
  468. allowed := false
  469. for _, t := range setting.Repository.Upload.AllowedTypes {
  470. t := strings.Trim(t, " ")
  471. if t == "*/*" || t == fileType {
  472. allowed = true
  473. break
  474. }
  475. }
  476. if !allowed {
  477. c.Error(http.StatusBadRequest, ErrFileTypeForbidden.Error())
  478. return
  479. }
  480. }
  481. upload, err := db.NewUpload(filepath.Join(fp, header.Filename), buf, file)
  482. if err != nil {
  483. c.Error(http.StatusInternalServerError, fmt.Sprintf("NewUpload: %v", err))
  484. return
  485. }
  486. log.Trace("New file uploaded by user[%d]: %s", c.UserID(), upload.UUID)
  487. c.JSONSuccess(map[string]string{
  488. "uuid": upload.UUID,
  489. })
  490. }
  491. func RemoveUploadFileFromServer(c *context.Context, f form.RemoveUploadFile) {
  492. if len(f.File) == 0 {
  493. c.Status(204)
  494. return
  495. }
  496. if err := db.DeleteUploadByUUID(f.File); err != nil {
  497. c.Error(500, fmt.Sprintf("DeleteUploadByUUID: %v", err))
  498. return
  499. }
  500. log.Trace("Upload file removed: %s", f.File)
  501. c.Status(204)
  502. }
  503. func CreateDatacite(c *context.Context) {
  504. dcname := path.Join("conf/datacite/datacite.yml")
  505. treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
  506. c.PageIs("Edit")
  507. c.RequireHighlightJS()
  508. c.RequireSimpleMDE()
  509. c.Data["IsYAML"] = true
  510. // safe to ignore error since we check for the asset at startup
  511. data, _ := bindata.Asset(dcname)
  512. c.Data["FileContent"] = string(data)
  513. c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
  514. c.Data["TreeNames"] = treeNames
  515. c.Data["TreePaths"] = treePaths
  516. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  517. c.Data["commit_summary"] = "Add information for publishing with DataCite"
  518. c.Data["commit_message"] = ""
  519. c.Data["commit_choice"] = "direct"
  520. c.Data["new_branch_name"] = ""
  521. c.Data["last_commit"] = c.Repo.Commit.ID
  522. c.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
  523. c.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
  524. c.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
  525. c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", setting.AppSubURL, c.Repo.Repository.FullName())
  526. c.Success(EDIT_FILE)
  527. }