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 7.2KB

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