Skip to content

Commit

Permalink
refactor(nextcloud): Define generated WebDAV props inside the generat…
Browse files Browse the repository at this point in the history
…ion script

Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Mar 27, 2024
1 parent 70f6112 commit f7dddf9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
68 changes: 54 additions & 14 deletions packages/nextcloud/generate_props.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,63 @@
import 'dart:io';

void main() {
final props = File('lib/src/webdav/props.csv').readAsLinesSync().map((line) => line.split(','));
final props = <String, Map<String, String>>{
'dav': {
'getlastmodified': 'String',
'getetag': 'String',
'getcontenttype': 'String',
'getcontentlength': 'int',
'resourcetype': 'WebDavResourcetype',
},
'oc': {
'id': 'String',
'fileid': 'String',
'favorite': 'int',
'comments-href': 'String',
'comments-count': 'int',
'comments-unread': 'int',
'downloadURL': 'String',
'owner-id': 'String',
'owner-display-name': 'String',
'size': 'int',
'permissions': 'String',
},
'nc': {
'note': 'String',
'data-fingerprint': 'String',
'has-preview': 'bool',
'mount-type': 'String',
'is-encrypted': 'int',
'metadata_etag': 'String',
'upload_time': 'int',
'creation_time': 'int',
'rich-workspace': 'String',
},
'ocs': {
'share-permissions': 'int',
},
'ocm': {
'share-permissions': 'String',
},
};

final valueProps = <String>[];
final findProps = <String>[];
final variables = <String>[];
for (final prop in props) {
final namespacePrefix = prop[0];
final namespaceVariable = convertNamespace(namespacePrefix);
final type = prop[2];
final name = prop[1];
final variable = namespacePrefix + name.toLowerCase().replaceAll(RegExp('[^a-z]'), '');
valueProps.add(
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: false,)\n final $type? $variable;",
);
findProps.add(
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: true, isSelfClosing: true,)\n final List<String?>? $variable;",
);
variables.add(variable);
for (final namespacePrefix in props.keys) {
for (final name in props[namespacePrefix]!.keys) {
final type = props[namespacePrefix]![name]!;

final namespaceVariable = convertNamespace(namespacePrefix);
final variable = namespacePrefix + name.toLowerCase().replaceAll(RegExp('[^a-z]'), '');
valueProps.add(
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: false,)\n final $type? $variable;",
);
findProps.add(
"@annotation.XmlElement(name: '$name', namespace: $namespaceVariable, includeIfNull: true, isSelfClosing: true,)\n final List<String?>? $variable;",
);
variables.add(variable);
}
}
File('lib/src/webdav/props.dart').writeAsStringSync(
[
Expand Down
27 changes: 0 additions & 27 deletions packages/nextcloud/lib/src/webdav/props.csv

This file was deleted.

0 comments on commit f7dddf9

Please sign in to comment.