You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /**
  2. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. *
  4. * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. import { subscribe } from '@nextcloud/event-bus'
  22. import { addScript, addStyle } from './legacy-loader'
  23. import {
  24. ajaxConnectionLostHandler,
  25. processAjaxError,
  26. registerXHRForErrorProcessing
  27. } from './xhr-error'
  28. import Apps from './apps'
  29. import { AppConfig, appConfig } from './appconfig'
  30. import { appSettings } from './appsettings'
  31. import appswebroots from './appswebroots'
  32. import Backbone from './backbone'
  33. import {
  34. basename,
  35. dirname,
  36. encodePath,
  37. isSamePath,
  38. joinPaths
  39. } from '@nextcloud/paths'
  40. import {
  41. build as buildQueryString,
  42. parse as parseQueryString
  43. } from './query-string'
  44. import Config from './config'
  45. import {
  46. coreApps,
  47. menuSpeed,
  48. PERMISSION_ALL,
  49. PERMISSION_CREATE,
  50. PERMISSION_DELETE,
  51. PERMISSION_NONE,
  52. PERMISSION_READ,
  53. PERMISSION_SHARE,
  54. PERMISSION_UPDATE,
  55. TAG_FAVORITE
  56. } from './constants'
  57. import ContactsMenu from './contactsmenu'
  58. import { currentUser, getCurrentUser } from './currentuser'
  59. import Dialogs from './dialogs'
  60. import EventSource from './eventsource'
  61. import { get, set } from './get_set'
  62. import { getCapabilities } from './capabilities'
  63. import {
  64. getHost,
  65. getHostName,
  66. getPort,
  67. getProtocol
  68. } from './host'
  69. import {
  70. getToken as getRequestToken
  71. } from './requesttoken'
  72. import {
  73. hideMenus,
  74. registerMenu,
  75. showMenu,
  76. unregisterMenu
  77. } from './menu'
  78. import { isUserAdmin } from './admin'
  79. import L10N, {
  80. getCanonicalLocale,
  81. getLanguage,
  82. getLocale
  83. } from './l10n'
  84. import {
  85. filePath,
  86. generateUrl,
  87. getRootPath,
  88. imagePath,
  89. linkTo,
  90. linkToOCS,
  91. linkToRemote,
  92. linkToRemoteBase
  93. } from './routing'
  94. import msg from './msg'
  95. import Notification from './notification'
  96. import PasswordConfirmation from './password-confirmation'
  97. import Plugins from './plugins'
  98. import search from './search'
  99. import { theme } from './theme'
  100. import Util from './util'
  101. import { debug } from './debug'
  102. import { redirect, reload } from './navigation'
  103. import webroot from './webroot'
  104. /** @namespace OC */
  105. export default {
  106. /*
  107. * Constants
  108. */
  109. coreApps,
  110. menuSpeed,
  111. PERMISSION_ALL,
  112. PERMISSION_CREATE,
  113. PERMISSION_DELETE,
  114. PERMISSION_NONE,
  115. PERMISSION_READ,
  116. PERMISSION_SHARE,
  117. PERMISSION_UPDATE,
  118. TAG_FAVORITE,
  119. /*
  120. * Deprecated helpers to be removed
  121. */
  122. /**
  123. * Check if a user file is allowed to be handled.
  124. * @param {string} file to check
  125. * @returns {Boolean}
  126. * @deprecated 17.0.0
  127. */
  128. fileIsBlacklisted: file => !!(file.match(Config.blacklist_files_regex)),
  129. addScript,
  130. addStyle,
  131. Apps,
  132. AppConfig,
  133. appConfig,
  134. appSettings,
  135. appswebroots,
  136. Backbone,
  137. ContactsMenu,
  138. config: Config,
  139. /**
  140. * Currently logged in user or null if none
  141. *
  142. * @type String
  143. * @deprecated use {@link OC.getCurrentUser} instead
  144. */
  145. currentUser,
  146. dialogs: Dialogs,
  147. EventSource,
  148. /**
  149. * Returns the currently logged in user or null if there is no logged in
  150. * user (public page mode)
  151. *
  152. * @since 9.0.0
  153. */
  154. getCurrentUser,
  155. isUserAdmin,
  156. L10N,
  157. /**
  158. * Ajax error handlers
  159. * @todo remove from here and keep internally -> requires new tests
  160. */
  161. _ajaxConnectionLostHandler: ajaxConnectionLostHandler,
  162. _processAjaxError: processAjaxError,
  163. registerXHRForErrorProcessing,
  164. /**
  165. * Capabilities
  166. *
  167. * @type {Array}
  168. * @deprecated 17.0.0 use OC.getCapabilities() instead
  169. */
  170. _capabilities: getCapabilities(),
  171. getCapabilities,
  172. /*
  173. * Legacy menu helpers
  174. */
  175. hideMenus,
  176. registerMenu,
  177. showMenu,
  178. unregisterMenu,
  179. /*
  180. * Path helpers
  181. */
  182. /**
  183. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  184. */
  185. basename,
  186. /**
  187. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  188. */
  189. encodePath,
  190. /**
  191. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  192. */
  193. dirname,
  194. /**
  195. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  196. */
  197. isSamePath,
  198. /**
  199. * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths
  200. */
  201. joinPaths,
  202. /**
  203. * Host (url) helpers
  204. */
  205. getHost,
  206. getHostName,
  207. getPort,
  208. getProtocol,
  209. /**
  210. * L10n
  211. */
  212. getCanonicalLocale,
  213. getLocale,
  214. getLanguage,
  215. /**
  216. * Loads translations for the given app asynchronously.
  217. *
  218. * @param {String} app app name
  219. * @param {Function} callback callback to call after loading
  220. * @return {Promise}
  221. * @deprecated 17.0.0 use OC.L10N.load instead
  222. */
  223. addTranslations: L10N.load,
  224. /**
  225. * Query string helpers
  226. */
  227. buildQueryString,
  228. parseQueryString,
  229. msg,
  230. Notification,
  231. PasswordConfirmation,
  232. Plugins,
  233. search,
  234. theme,
  235. Util,
  236. debug,
  237. filePath,
  238. generateUrl,
  239. get: get(window),
  240. set: set(window),
  241. getRootPath,
  242. imagePath,
  243. redirect,
  244. reload,
  245. requestToken: getRequestToken(),
  246. linkTo,
  247. linkToOCS,
  248. linkToRemote,
  249. linkToRemoteBase,
  250. /**
  251. * Relative path to Nextcloud root.
  252. * For example: "/nextcloud"
  253. *
  254. * @type string
  255. *
  256. * @deprecated since 8.2, use OC.getRootPath() instead
  257. * @see OC#getRootPath
  258. */
  259. webroot
  260. }
  261. // Keep the request token prop in sync
  262. subscribe('csrf-token-update', e => {
  263. OC.requestToken = e.token
  264. // Logging might help debug (Sentry) issues
  265. console.info('OC.requestToken changed', e.token)
  266. })