file.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  3. *
  4. * @author Julius Härtl <jus@bitgrid.net>
  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. */
  22. import FileMimeType from './FileMimeType'
  23. import { stringValidator, validateIPv4, validateIPv6 } from './../../helpers/validators'
  24. import FileSystemTag from './FileSystemTag'
  25. const FileChecks = [
  26. {
  27. class: 'OCA\\WorkflowEngine\\Check\\FileName',
  28. name: t('workflowengine', 'File name'),
  29. operators: [
  30. { operator: 'is', name: t('workflowengine', 'is') },
  31. { operator: '!is', name: t('workflowengine', 'is not') },
  32. { operator: 'matches', name: t('workflowengine', 'matches') },
  33. { operator: '!matches', name: t('workflowengine', 'does not match') }
  34. ],
  35. placeholder: (check) => {
  36. if (check.operator === 'matches' || check.operator === '!matches') {
  37. return '/^dummy-.+$/i'
  38. }
  39. return 'filename.txt'
  40. },
  41. validate: stringValidator
  42. },
  43. {
  44. class: 'OCA\\WorkflowEngine\\Check\\FileMimeType',
  45. name: t('workflowengine', 'File MIME type'),
  46. operators: [
  47. { operator: 'is', name: t('workflowengine', 'is') },
  48. { operator: '!is', name: t('workflowengine', 'is not') },
  49. { operator: 'matches', name: t('workflowengine', 'matches') },
  50. { operator: '!matches', name: t('workflowengine', 'does not match') }
  51. ],
  52. component: FileMimeType
  53. },
  54. {
  55. class: 'OCA\\WorkflowEngine\\Check\\FileSize',
  56. name: t('workflowengine', 'File size (upload)'),
  57. operators: [
  58. { operator: 'less', name: t('workflowengine', 'less') },
  59. { operator: '!greater', name: t('workflowengine', 'less or equals') },
  60. { operator: '!less', name: t('workflowengine', 'greater or equals') },
  61. { operator: 'greater', name: t('workflowengine', 'greater') }
  62. ],
  63. placeholder: (check) => '5 MB',
  64. validate: (check) => check.value.match(/^[0-9]+[ ]?[kmgt]?b$/i) !== null
  65. },
  66. {
  67. class: 'OCA\\WorkflowEngine\\Check\\RequestRemoteAddress',
  68. name: t('workflowengine', 'Request remote address'),
  69. operators: [
  70. { operator: 'matchesIPv4', name: t('workflowengine', 'matches IPv4') },
  71. { operator: '!matchesIPv4', name: t('workflowengine', 'does not match IPv4') },
  72. { operator: 'matchesIPv6', name: t('workflowengine', 'matches IPv6') },
  73. { operator: '!matchesIPv6', name: t('workflowengine', 'does not match IPv6') }
  74. ],
  75. placeholder: (check) => {
  76. if (check.operator === 'matchesIPv6' || check.operator === '!matchesIPv6') {
  77. return '::1/128'
  78. }
  79. return '127.0.0.1/32'
  80. },
  81. validate: (check) => {
  82. if (check.operator === 'matchesIPv6' || check.operator === '!matchesIPv6') {
  83. return validateIPv6(check.value)
  84. }
  85. return validateIPv4(check.value)
  86. }
  87. },
  88. {
  89. class: 'OCA\\WorkflowEngine\\Check\\FileSystemTags',
  90. name: t('workflowengine', 'File system tag'),
  91. operators: [
  92. { operator: 'is', name: t('workflowengine', 'is tagged with') },
  93. { operator: '!is', name: t('workflowengine', 'is not tagged with') }
  94. ],
  95. component: FileSystemTag
  96. }
  97. ]
  98. export default FileChecks